rsync runs fine in terminal but not in cron
I have run an rsync command from the terminal and it works fine. When I try it in cron or even sudo cron it fails to work.
I have the machine set up with SSH keys so no password is required. This is how I have entered it onto cron: */5 * * * * rsync -av -e "ssh -p 2280" --delete /home/tim/Documents/pi-2-black tim@192.168.0.80:/home/tim/Documents/ Where am I going wrong? Many thanks Tim |
Try putting the full path to the rsync command in there, e.g., /usr/bin/rsync . . .
|
1) I've run into this kind of cron vs terminal issue myself and the first thing to do is pipe both stdin and stderr to the same log file.
So do something like this: */5 * * * * rsync -av -e "ssh -p 2280" --delete /home/tim/Documents/pi-2-black tim@192.168.0.80:/home/tim/Documents/ 2>&1 | tee -a ~/rsync_documents.log 2) Use rsync's --progress and --verbose options to see more of what, if anything, did get transferred |
Quote:
Also, are the environment variables SSH_AGENT_PID and SSH_AUTH_SOCK being properly filled in cron? |
There are several cron daemons. Try to identify yours (dixie cron, vixie cron, fcron, ...). The one I have is dixie cron and it's quite restrictive: It uses the shell /bin/sh, which on my distro is not bash. It uses only four environment variables: USER, LOGNAME, HOME, and SHELL...
To avoid problems, simply put your rsync command in a shell script with a nice shebang at the beginning (#!/bin/bash for me) and put the full path to the script in your cron job. This way, your rsync command will run in the same environment as it does in your terminal. Be careful though at the ID under which the job will run (your id or root ?). |
Quote:
|
All times are GMT -5. The time now is 09:58 AM. |