LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Rsync command to/from CIFS share does not work in cron, works in terminal? (https://www.linuxquestions.org/questions/linux-software-2/rsync-command-to-from-cifs-share-does-not-work-in-cron-works-in-terminal-4175494618/)

rylan76 02-12-2014 05:04 AM

Rsync command to/from CIFS share does not work in cron, works in terminal?
 
Hi guys

I've got the following rsync command to sync files to and from CIFS shares hosted on a Windows 8 box:

To rsync from a CIFS share on Windows 8, in the term, I do

Code:

/usr/bin/rsync -avz --progress --no-whole-file /mnt/remote_software/* /home/earth/software/.
To rsync to a CIFS share on Windows 8, in the term, I do

Code:

/usr/bin/rsync -avz --progress --no-whole-file /home/earth/software/* /mnt/remote_software/.
I mount the above CIFS share via this command (192.168.1.1 being my Windows 8 fileserver) - the share's name is "software" on the Windows machine.

Code:

mount -t cifs //192.168.1.1/software /mnt/remote_software -o username=myname,password=mypass
The above works fine, I can sync files in both directions no problem, browse the share, save new files to it, and read files from this CIFS partition while the files are actually on the Windows box.

However, as soon as I try to touch this share from an rsync-spawned cron, rsync does not work.

My crontab looks like this:
Code:

30 00 * * * sh -f /root/do_backup.sh > errors.txt 2>&1
where do_backup.sh is

Code:

/usr/bin/rsync -avz --progress --no-whole-file /mnt/remote_software/* /home/earth/software/.
Permissions on do_backup.sh are -rwxr-xr-x - eg. executable for all.

E. g. the command I pass from the cron calls do_backup.sh - if I do

Code:

sh -f /root/do_backup.sh
while in a terminal session, it works fine. The files are rsynced from the CIFS share (actually on my Windows machine) to my local Linux machine's /home/earth/software directory.

If cron calls sh -f /root/do_backup.sh rsync cannot see the /mnt/remote_software CIFS share, and the rsync fails.

Errors.txt then contains

Code:

sending incremental file list
rsync: link_stat "/mnt/remote_software/*" failed: No such file or directory (2)

If rsync is run via cron on a CIFS share, it simply does NOT work.

When in the terminal, I run the manual rsync command while logged in as root.

I'm on Centos 6

Any ideas as to why stuff spawned in cron (running as root, correct?) cannot see CIFS shares?

To test I also put a df -mh > mounts.txt into the crontab a minute before the rsync script's start, and mounts.txt clearly contains

Code:

//192.168.1.1/software/                  1.9T  1.3T  601G 68% /mnt/remote/software
which means at cron level, "df" CAN see the share and enumerate it, return its size, etc. - yet the rsync that runs 60 seconds later can't?

Any ideas what is going on and how to fix it?

Thanks!

pingu 02-12-2014 06:37 AM

I think the problem is the wildcard '*', it is read literally.
To test that, remove the '*' and add a directory instead.

rylan76 02-12-2014 09:53 AM

Hi

Thanks of the reply!

Ok I'll try to remove the trailing * and . and see what happens...

Thanks again

rylan76 02-17-2014 03:34 AM

That was the solution! I removed the * as trailing character for the source rsync specification and removed . as trailing character in the rsync target specification.

The rsync job now runs fine if triggered from cron.

Thanks for the help!


All times are GMT -5. The time now is 02:10 AM.