LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-16-2011, 10:19 AM   #1
Ravishankarappa
LQ Newbie
 
Registered: Aug 2011
Posts: 5

Rep: Reputation: Disabled
rsync not running in cron job; please help


I am trying to use rsync in a cron job but looks like cron is not running. Here is the setup:
Host = host.xxx.xxx
Dest = dest.xxx.xxx

The folder to copy from host is /home/mine and it should copy (rsync) to /home/mine in destination machine.
Since I like to use ssh for this and didn’t want password question to pop up (because it should be in cron job), I followed instructions in the following instruction.

• Generate a public key with ssh-keygen as the user that you will be connecting with rsync. Choose a good pass phrase.
• Insert the key you just created into ~/.ssh/authorized_keys.
• Copy the ~/.ssh/authorized_keys file to the other machine(s).
• Set permissions (chmod 644) for ~/.ssh/authorized_keys, if needed.


Then I tried manually the following command in host machine and it works.
rsync -avz -e ssh /home/mine mine@dest.xxx.xxx:/home/mine

Then in host (host.xxx.xxx) I did crontab –e and entered the following:
0 11 * * * rsync -avz -e ssh /home/mine mine@dest.xxx.xxx:/home/mine

I was hoping that at 11 AM it would run, but it didn’t. What am I doing wrong? Could someone please help?

-Ravi
 
Old 08-16-2011, 10:27 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Since CRON uses a limited PATH, try to use the whole path to the commands and files.

Kind regards
 
Old 08-16-2011, 11:15 AM   #3
Ravishankarappa
LQ Newbie
 
Registered: Aug 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by repo View Post
Since CRON uses a limited PATH, try to use the whole path to the commands and files.

Kind regards
Changed command from rsync to /usr/bin/rsync but its still no go. Any other hints?

-Ravi
 
Old 08-16-2011, 11:33 AM   #4
brian-ocs
LQ Newbie
 
Registered: Jul 2011
Location: San Diego, CA
Distribution: CentOS 6, Linux Mint Debian Edition
Posts: 18

Rep: Reputation: 1
What account are you using to run the cron job? Is the job scheduled in the "mine" account crontab? What happens if you schedule it with the root account?
 
Old 08-16-2011, 11:33 AM   #5
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Any pointers in the log files?

Kind regards
 
Old 08-16-2011, 11:37 AM   #6
Ravishankarappa
LQ Newbie
 
Registered: Aug 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
OK. I changed the command as follows to write the log file.

0 11 * * * rsync -avz -e ssh /home/mine mine@dest.xxx.xxx:/home/mine >>/tmp/rsyncA.log 2>&1 .
The log file says the /home/mine is skipped. Why did it do that? I had just created a dummy file in /home/mine to verify that the files are copied to destination and I dont see it in the destination at all !

_Ravi
 
Old 08-16-2011, 11:46 AM   #7
Ravishankarappa
LQ Newbie
 
Registered: Aug 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by brian-ocs View Post
What account are you using to run the cron job? Is the job scheduled in the "mine" account crontab? What happens if you schedule it with the root account?
Yes, the job is run from "mine" account. To run it as root, I will have to generate SSH key and append it the existing keys right? Or else using rsync with ssh will prompt password to be entered which would be a problem if I want to run it in cron. (I think).

-Ravi
 
Old 08-16-2011, 12:30 PM   #8
Ravishankarappa
LQ Newbie
 
Registered: Aug 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by brian-ocs View Post
What account are you using to run the cron job? Is the job scheduled in the "mine" account crontab? What happens if you schedule it with the root account?
OK. I ran it as root. The log file is as follows:

rsync: push_dir#3 "/root/mine@mine.xxx.xxx/home" failed: No such file or directory
rsync error: errors selecting input/output files, dirs (code 3) at main.c(545) [receiver=2.6.8]
rsync: connection unexpectedly closed (8 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(463) [sender=2.6.8]
skipping directory /home/mine

Help please!

-Ravi
 
Old 08-17-2011, 12:11 PM   #9
brian-ocs
LQ Newbie
 
Registered: Jul 2011
Location: San Diego, CA
Distribution: CentOS 6, Linux Mint Debian Edition
Posts: 18

Rep: Reputation: 1
Try running the cron job like this:
Code:
0 11 * * * rsync -avz -e ssh /home/mine mine@dest.xxx.xxx:/home/mine
without the
Quote:
>>/tmp/rsyncA.log 2>&1 .
 
  


Reply



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
Cron job is not running dhirendrs Programming 1 08-25-2010 04:37 AM
Cron Job is not running akshathajagadish Linux - Newbie 2 10-15-2009 07:21 PM
Running a Cron Job landysaccount Linux - Newbie 6 02-04-2009 05:29 PM
how can i run rsync as a cron job using public keys authentication disorderly Linux - Server 14 03-13-2008 09:51 PM
Cannot execute rsync as a cron job jdaniels73 Linux - Software 2 09-03-2006 05:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:25 PM.

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
Open Source Consulting | Domain Registration