> Hugh McIntyre wrote:
> > Kyle McDonald wrote:
> >> Any advice on a good way to acquire a lock in a
> shell script?
> >
> > 1. Install procmail.
> >
> > 2. Use the following:
> >
> > if lockfile $FILE ; then
> > # do stuff with the file locked....
> > rm -f $FILE
> > fi
>
> Hmm. An important correction is, generally, to use:
>
> lockfile ${FILE}.lock
> # do stuff
> rm -f ${FILE}.lock
> ^^^^^
>
> I.e. don't remove the original file, of course...
Even better would be:
remove_lock() {
rm -f "${lock_file}"
}
trap remove_lock 0 1 2 3 6 15
if lockfile "${lock_file}" ; then
.....
fi
Making sure you clean up your lockfiles is important....
Paul
--
This message posted from opensolaris.org