LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-28-2011, 10:54 AM   #1
vielmaj
LQ Newbie
 
Registered: Jun 2009
Posts: 24
Blog Entries: 1

Rep: Reputation: 0
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
 
Old 03-28-2011, 11:06 AM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653
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
 
Old 03-28-2011, 11:17 AM   #3
vielmaj
LQ Newbie
 
Registered: Jun 2009
Posts: 24

Original Poster
Blog Entries: 1

Rep: Reputation: 0
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)
 
Old 03-28-2011, 11:35 AM   #4
pingu
Senior Member
 
Registered: Jul 2004
Location: Skuttunge SWEDEN
Distribution: Debian preferably
Posts: 1,350

Rep: Reputation: 127Reputation: 127
Check permissions & ownership - cronjobs don't always run with root privileges.
 
Old 03-28-2011, 11:42 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Quote:
Originally Posted by vielmaj View Post
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.
 
Old 03-28-2011, 12:30 PM   #6
vielmaj
LQ Newbie
 
Registered: Jun 2009
Posts: 24

Original Poster
Blog Entries: 1

Rep: Reputation: 0
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
 
Old 03-28-2011, 12:41 PM   #7
vielmaj
LQ Newbie
 
Registered: Jun 2009
Posts: 24

Original Poster
Blog Entries: 1

Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cant get my cronjob to work kraffslol Linux - Software 5 12-27-2009 10:58 PM
Update doesn´t work AnLi Linux - Newbie 2 10-03-2008 02:51 AM
Cronjob does not work niner710 Linux - Newbie 11 05-07-2008 03:45 AM
grub doesn`t work Atomtomate Linux - Desktop 6 01-16-2007 07:58 AM
python doesn´t work little_ball Linux - Newbie 4 12-04-2004 09:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration