Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
03-28-2011, 11:54 AM
|
#1
|
LQ Newbie
Registered: Jun 2009
Posts: 24
Rep:
|
cronjob rsync doesn't work
I have a computer that I would like to backup the home directory onto a server. I created a script called wien_backup.sh that contains the following:
#!/bin/bash -l
/usr/bin/rsync -rv --delete-after --ignore-errors -e /usr/bin/ssh root@wngr403-unix2:/home/ /space/systemimager/Wien/
where wngr403-unix2 is the computer I am backing up, and the script is ran from the server. If I run the script by itself, it works just fine. If I run it as a cronjob, the /var/log/syslog says it ran, but it does nothing.
Any help is appreciated.
Jason
|
|
|
03-28-2011, 12:06 PM
|
#2
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
change #!/bin/bash -l to #!/bin/bash -x
and add a > /root/tmp.out to your crontab command so we can see what it is erroring on.
Code:
5 * * * * /root/somescript.sh > /root/tmp.out
|
|
|
03-28-2011, 12:17 PM
|
#3
|
LQ Newbie
Registered: Jun 2009
Posts: 24
Original Poster
Rep:
|
I did what you said and the /root/tmp.out is empty. Here is how it is listed when I run crontab -l
13 9 * * * /root/bin/wien_backup.sh > /root/tmp.out
And it shows this in the /var/log/syslog file
Mar 28 09:13:01 physics-server /USR/SBIN/CRON[24499]: (root) CMD (/root/bin/wien_backup.sh > /root/tmp.out)
|
|
|
03-28-2011, 12:35 PM
|
#4
|
Senior Member
Registered: Jul 2004
Location: Skuttunge SWEDEN
Distribution: Debian preferably
Posts: 1,350
Rep:
|
Check permissions & ownership - cronjobs don't always run with root privileges.
|
|
|
03-28-2011, 12:42 PM
|
#5
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
Originally Posted by vielmaj
I did what you said and the /root/tmp.out is empty.
|
This confirms that the cron job has been executed, since redirection causes the shell to create an empty file and to open the related file descriptor. Then the command is executed and the log file is populated. Since rsync uses the -v option, you should see something in the log file. This means that the rsync command has not been executed for some reason. Most likely the script lacks the execution permissions, as already suggested.
|
|
|
03-28-2011, 01:30 PM
|
#6
|
LQ Newbie
Registered: Jun 2009
Posts: 24
Original Poster
Rep:
|
I believe my problem is with ssh itself. I tried the following script that tells me who is logged in to each machine.
#!/bin/bash
for i in `seq 1 9`;
do
ssh wngr412-pc0$i.physics.oregonstate.edu "uname -n;last | grep logged | grep -v root"
done
for j in `seq 10 26`;
do
ssh wngr412-pc$j.physics.oregonstate.edu "uname -n;last | grep logged | grep -v root"
done
for k in `seq 1 9`;
do
ssh wngr497-pc0$k.physics.oregonstate.edu "uname -n; last | grep logged | grep -v root"
done
i=3
ssh wngr40$i-unix2.physics.oregonstate.edu "uname -n; last | grep logged | grep -v root"
exit 0
If I run it by itself I get the following output
wngr412-pc01.physics.oregonstate.edu
wngr412-pc02.physics.oregonstate.edu
wngr412-pc03.physics.oregonstate.edu
wngr412-pc04.physics.oregonstate.edu
wngr412-pc05.physics.oregonstate.edu
wngr412-pc06.physics.oregonstate.edu
wngr412-pc07.physics.oregonstate.edu
ssh: connect to host wngr412-pc08.physics.oregonstate.edu port 22: No route to host
wngr412-pc09.physics.oregonstate.edu
wngr412-pc10.physics.oregonstate.edu
wngr412-pc11.physics.oregonstate.edu
wngr412-pc12.physics.oregonstate.edu
wngr412-pc13.physics.oregonstate.edu
wngr412-pc14.physics.oregonstate.edu
wngr412-pc15.physics.oregonstate.edu
wngr412-pc16.physics.oregonstate.edu
wngr412-pc17.physics.oregonstate.edu
wngr412-pc18.physics.oregonstate.edu
wngr412-pc19.physics.oregonstate.edu
wngr412-pc20.physics.oregonstate.edu
wngr412-pc21.physics.oregonstate.edu
wngr412-pc22.physics.oregonstate.edu
wngr412-pc23.physics.oregonstate.edu
wngr412-pc24.physics.oregonstate.edu
wngr412-pc25.physics.oregonstate.edu
wngr412-pc26.physics.oregonstate.edu
wngr497-pc01.physics.oregonstate.edu
wngr497-pc02.physics.oregonstate.edu
wngr497-pc03.physics.oregonstate.edu
wngr497-pc04.physics.oregonstate.edu
wngr497-pc05.physics.oregonstate.edu
wngr497-pc06.physics.oregonstate.edu
wngr497-pc07.physics.oregonstate.edu
wngr497-pc08.physics.oregonstate.edu
wngr497-pc09.physics.oregonstate.edu
vielmaj pts/0 slide.physics.or Mon Mar 28 10:22 still logged in
wngr403-unix2
janet pts/4 wngr485-mac2.sci Mon Mar 28 09:53 still logged in
vielmaj pts/3 slide.physics.or Mon Mar 28 08:05 still logged in
But, if I run it as a cronjob, I get the following
wngr412-pc01.physics.oregonstate.edu
wngr412-pc02.physics.oregonstate.edu
wngr412-pc03.physics.oregonstate.edu
wngr412-pc04.physics.oregonstate.edu
wngr412-pc05.physics.oregonstate.edu
wngr412-pc06.physics.oregonstate.edu
wngr412-pc07.physics.oregonstate.edu
wngr412-pc09.physics.oregonstate.edu
wngr412-pc10.physics.oregonstate.edu
wngr412-pc11.physics.oregonstate.edu
wngr412-pc12.physics.oregonstate.edu
wngr412-pc13.physics.oregonstate.edu
wngr412-pc14.physics.oregonstate.edu
wngr412-pc15.physics.oregonstate.edu
wngr412-pc16.physics.oregonstate.edu
wngr412-pc17.physics.oregonstate.edu
wngr412-pc18.physics.oregonstate.edu
wngr412-pc19.physics.oregonstate.edu
wngr412-pc20.physics.oregonstate.edu
wngr412-pc21.physics.oregonstate.edu
wngr412-pc22.physics.oregonstate.edu
wngr412-pc23.physics.oregonstate.edu
wngr412-pc24.physics.oregonstate.edu
wngr412-pc25.physics.oregonstate.edu
wngr412-pc26.physics.oregonstate.edu
wngr497-pc01.physics.oregonstate.edu
wngr497-pc02.physics.oregonstate.edu
wngr497-pc03.physics.oregonstate.edu
wngr497-pc04.physics.oregonstate.edu
wngr497-pc05.physics.oregonstate.edu
wngr497-pc06.physics.oregonstate.edu
wngr497-pc07.physics.oregonstate.edu
wngr497-pc08.physics.oregonstate.edu
wngr497-pc09.physics.oregonstate.edu
vielmaj pts/0 slide.physics.or Mon Mar 28 10:22 still logged in
|
|
|
03-28-2011, 01:41 PM
|
#7
|
LQ Newbie
Registered: Jun 2009
Posts: 24
Original Poster
Rep:
|
Thanks everyone for their help. I figured out the problem.
When I created the ssh-key for passwordless logins to machine wngr403-unix2, I created it while being logged in to the server from a remote hosts. The key in /root/.ssh/authorized_keys ended with abacus.physics.oregonstate.edu instead of root@physics-server.physics.oregonstate.edu. Once I created the ssh key from the server itself, the script worked.
|
|
|
All times are GMT -5. The time now is 03:18 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|