On Tue, Aug 29, 2006 at 11:13:43AM -0700, Scott Silva wrote:
...of a shell script for rsync that won't start again if it is already running? I thought of using a lock file, but what if it is killed mid script or bombs?
1. Use a directory for locking instead of a file, because testing for existence and creating the directory is an atomic operation.
2. Use trap to remove the lockdir
so basically:
if ! mkdir $LOCKDIR ; then echo "Lockdir exists; aborting." exit 1 fi trap "rmdir $LOCKDIR; echo 'mirror script exiting'" EXIT TERM INT QUIT
rsync $RSYNCOPTS $REMOTE $LOCAL