LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-12-2011, 06:10 AM   #1
Prabagaran
LQ Newbie
 
Registered: Mar 2009
Posts: 17

Rep: Reputation: Disabled
Question 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.
 
Old 04-12-2011, 06:20 AM   #2
Fracker
Member
 
Registered: Mar 2009
Posts: 90

Rep: Reputation: 0
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?
 
Old 04-12-2011, 06:51 AM   #3
Prabagaran
LQ Newbie
 
Registered: Mar 2009
Posts: 17

Original Poster
Rep: Reputation: Disabled
Question

Hi Fracker,

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.

Regards,
PL.
 
Old 04-12-2011, 09:24 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
Old 04-12-2011, 09:31 PM   #5
jcalzare
Member
 
Registered: Aug 2009
Location: Chicago
Distribution: CentOS
Posts: 114

Rep: Reputation: 34
If you are going to automate processes that require sudo, make sure to comment out this line in /etc/sudoers:

Defaults requiretty
 
Old 04-12-2011, 11:55 PM   #6
Fracker
Member
 
Registered: Mar 2009
Posts: 90

Rep: Reputation: 0
Try

"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"
 
Old 04-15-2011, 01:39 AM   #7
Prabagaran
LQ Newbie
 
Registered: Mar 2009
Posts: 17

Original Poster
Rep: Reputation: Disabled
Thumbs up

All,

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

and

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.

Cheers
PL.
 
  


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
[SOLVED] rsync, crontab and backing up files trucutu Linux - Newbie 4 04-11-2011 06:17 PM
Crontab rsync does not backup to NAS device Astol Linux - Software 1 09-24-2008 12:04 AM
Rsync and Crontab not playing well together phillc Linux - Newbie 9 11-08-2007 10:22 AM
Backup with rsync and crontab gjblackford Linux - General 4 01-04-2007 08:53 AM
rsync in crontab loonykroons Linux - Software 3 11-28-2006 03:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:14 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