[SOLVED] rsync execution issue with crontab - Have given full path to rsync too!!
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
rsync execution issue with crontab - Have given full path to rsync too!!
Hi,
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:
#!/bin/bash
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.
Thanks,
PL.
Last edited by Prabagaran; 04-12-2011 at 06:12 AM.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.