LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   rsync not running in cron job; please help (https://www.linuxquestions.org/questions/linux-newbie-8/rsync-not-running-in-cron-job%3B-please-help-897620/)

Ravishankarappa 08-16-2011 10:19 AM

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

repo 08-16-2011 10:27 AM

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

Kind regards

Ravishankarappa 08-16-2011 11:15 AM

Quote:

Originally Posted by repo (Post 4444647)
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

brian-ocs 08-16-2011 11:33 AM

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?

repo 08-16-2011 11:33 AM

Any pointers in the log files?

Kind regards

Ravishankarappa 08-16-2011 11:37 AM

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

Ravishankarappa 08-16-2011 11:46 AM

Quote:

Originally Posted by brian-ocs (Post 4444726)
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

Ravishankarappa 08-16-2011 12:30 PM

Quote:

Originally Posted by brian-ocs (Post 4444726)
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

brian-ocs 08-17-2011 12:11 PM

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 .


All times are GMT -5. The time now is 03:38 PM.