Re: [CentOS] Any one have a good example...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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



-- 
Matthew Miller           mattdm@xxxxxxxxxx          <http://mattdm.org/>
Boston University Linux      ------>              <http://linux.bu.edu/>
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux