Rsync script works but not on schedule via cron

I'm trying to execute a shell script to start an rsync process that syncs a local directory on a server with an NFS mount installed on the same server. I run the script as "root" that "sudo on a user who has write permission on the NFS mount and runs another shell script that does" rsync ".

When I run this script manually as "root", the script runs successfully. However, when I plan to run the script via cron, the "rsync" process starts but does not end, stopping at the file listing stage.

This is the script, "exec_NFS_rsync.sh", which I run as "root":

#!/bin/bash

sudo -u nfsuser /path/to/scripts/nfs_rsync/scripts/NFS_rsync.sh

      

This is the content of "NFS_rsync.sh":

#!/bin/bash

##
## VARIABLES
##

# rsync binary
rsync="/usr/bin/rsync"

# Source
sourcedir="/path/to/source/files/"

# Destination
destdir="/path/to/destination/nfs/mount/"

# Exclude
exclude="--exclude=*.tmp --exclude=tmp/ --exclude=*.lck"

# Log file
log_file="/path/to/log/folder/NFS_rsync.log"

##
## SCRIPT
##

# Check if the log file exists
if [ ! -e $log_file ]; then
        touch $log_file
fi

if [ ! -d $destdir ]; then
        echo "Log destination directory doesn't seem to exist. Please investigate"
        exit 2
fi


# Start entry in the log
echo "$(date "+%Y-%m-%d %k:%M:%S") - Local Storage to NFS Sync started." >> $log_file

# Start sync NFS to Local
`$rsync -av --stats --delete $exclude $sourcedir $destdir >> $log_file`

echo "$(date "+%Y-%m-%d %k:%M:%S") - Local Storage to NFS Sync completed." >> $log_file


# End entry in the log
echo "" >> $log_file
exit

      

This is the output I get when running with 'cron':

2012-04-05 16:20:01 - Local Storage to NFS Sync started.
building file list ... 2012-04-05 16:20:01 - Local Storage to NFS Sync completed.

      

Note that the "building file list" is never marked "done".

There is no file transfer.

This is the "crontab" entry:

*/10 * * * * /path/to/scripts/nfs_rsync/scripts/exec_NFS_rsync.sh

      

If I run it manually, I get full verbose output and transfers succeed, after which statistics are presented (I won't include it because it is long).

I don't think this is a permissions issue because I can execute the "exec_NFS_rsync.sh" script as "root" from the shell, and also execute the "NFS_rsync.sh" script directly as "nfsuser".

This is the "fstab" entry for an NFS mount:

nfsfiler:/path/to/nfs/mount /path/to/destination/nfs/mount/      nfs     hard,intr,nfsvers=3,rw,rsize=32768,wsize=32768 0 0

      

Thanks in advance for any help you can provide.

+3


source to share


1 answer


How about an indication

*/10 * * * * su - l nfsuser -c /path/to/scripts/nfs_rsync/scripts/NFS_rsync.sh

      



in the root of the crontab?

0


source







All Articles