rsync execution issue with crontab - Have given full path to rsync too!!
I have a tiny shell script to rsync files between two servers and remove the source files.
This script works fine, when it has been initiated manually or even when the rsync command is executed on the command line.
But the same script doesn't work, when I try to automate it through crontab.
Script looks like this @ /mnt/xyz/folder/rsync.sh:
chown abc.abc /mnt/source/folder/ -R
sudo -u abc /usr/bin/rsync -azvH --remove-source-files /mnt/source/folder/ abc@destination-ip:/mnt/destinationfolder/
I am using 'abc' user to execute this rsync, instead of root, as root login to servers are restricted in all of our servers, by us.
As I mentioned earlier, manual execution works like charm!!
When this rsync.sh is initiated through crontab, it runs the first command(chown abc.abc ...) perfectly without any issues. But the second line is not at all executed, and there is no log entry i can find at /mnt/xyz/folder/rsync.log
Crontab entry would like this:
*/10 * * * * /mnt/xyz/folder/rsync.sh >> /mnt/xyz/folder/rsync.log
Any help would be appreciated.
And, if i am doing something wrong in my script or crontab, please guide me in right path.
Also, if any more information needed from me, i would do that.
Check your mails + Crontab logs, and post the error here.
Also check "ps aux | grep rsync", i think your previous command will also be in the memory.
Also i didn't find password given for 'abc' user (or you have transfered keys between both servers)
Lastly, from which user your cron this script?
Thanks for your inputs.
1. I don't see any mail to root & it will be great, if you could let me know how to check crontab log.
When I checked for /var/log/messages, no entries regarding crontab/rsync is found.
Also under /var/spool/mail/root, no logs i could find.
2. ps aux |grep rsync gave me this:
root 11024 0.0 0.0 6064 612 pts/1 R+ 04:36 0:00 grep rsync
3. I have key-authentication for abc user.
4. Cron runs as root. Also, in the script, first line is executed as root(so that the file permissions could be changed,otherwise not). And the second line(rsync) will be executed as 'abc' user.
Also, as I mentioned in my initial post, the whole script is running fine, if it is executed in command line, manually like this:
]#sudo -u abc /usr/bin/rsync -azvH --remove-source-files /mnt/source/folder/ abc@destination-ip:/mnt/destinationfolder/
Any more information needed from me, would like to share.
It's possible sudo isn't in the default env for cron; it's best to provide the path to ALL external cmds (ie cmds not built-in to current shell).
Don't have a Linux system to check in front of me.
If you are going to automate processes that require sudo, make sure to comment out this line in /etc/sudoers:
"su -u abc -c "/usr/bin/rsync -azvH --remove-source-files /mnt/source/folder/ abc@destination-ip:/mnt/destinationfolder/"
Crontab logs are normally saved at "/var/log/crontab"
I got a different solution for my query by running crontab under root and abc as mentioned below.
I made an entry at root's crontab as:
*/39 * * * * chown abc.abc /mnt/source/folder/ -R
I made an entry at abc's crontab as: (#crontab -u abc -e)
*/40 * * * * /usr/bin/rsync -azvH --remove-source-files /mnt/source/folder/ abc@destination-ip:/mnt/destinationfolder/
This started working like a charm !! :)
Anyways, thanks all for your time spent on my query.
|All times are GMT -5. The time now is 04:31 AM.|