[CentOS-mirror] About Cron script with lock file

Olivier Thauvin nanardon at nanardon.zarb.org
Wed Jan 24 22:33:11 UTC 2007


Le Wednesday 24 January 2007 23:16, Matthew Martz a écrit :
> On Wed, January 24, 2007 2:44 am, Kelphon wrote:
> > Dear David,
> >
> >          Does your cron script for centos mirror work now?
> >
> >          Could you please send your cron script with lockfile to us ;)
> >
> > Thanks a lot!
>
> Simple mirror script:

> # no need to edit anything below here
> if [ -f $LOCKFILE ]
> then
>         echo Lock file exists...Exiting...
>         exit 0

This part is not safe. If computer get down, or script killed, the lock will 
stay.

To avoid such issue I used in past:
===========

if [ -f ${lock} ]; then
        [ -d /proc/`cat ${lock}` ] && exit 0
fi

clean () {
        rm -fr ${lock}
}

trap clean 0

echo -n $$ > ${lock}

===========

Now I used more sophisticated tools like mmm (http://mmm.zarb.org/) to 
massivelly run rsync job.

The code above is of course under GPL or any other license which allow you 
reuse it and/or improve it ;)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.centos.org/pipermail/centos-mirror/attachments/20070124/a9b83fb7/attachment.bin


More information about the CentOS-mirror mailing list