dotlockfile
Michael Hipp
Michael
Tue Jul 24 15:06:50 PDT 2007
Jay Nugent wrote:
> Greetings,
>
> On Tue, 24 Jul 2007, Michael Hipp wrote:
>
>> Does anyone have a bash script that does essentially the same thing as
>> the 'dotlockfile' utility?
>>
>> I have a system without dotlockfile but I need that functionality to
>> keep a script from clobbering itself.
>
> I just ran into this problem earlier today. So I'll be implementing
> this lockfile code into my scripts tonight.
>
>
> #
> #==================================================================
> # Test to see if we have a LOCK file (i.e. a copy is still running)
> #
> LCKFYLE="/home/wwnet/LCK-wwnet-dialusage"
> #
> if [ -f $LCKFYLE ]; then
> /bin/mail -s "$LCKFYLE exists" jjn at nuge.com
> exit 0
> else
> touch $LCKFYLE
> #
> #==================================================================
> # We wrap the rest of the code from here on...
> #
>
> [ place the rest of your script in here ]
>
> #
> #==================================================================
> #
> # ... the end of the LCKFYLE test wrapper
> #
> rm $LCKFYLE
> #
> fi
> #
> #----------
> #
> # - end -
> #
Thanks. Unfortunately this doesn't handle the "stale lock file" syndrome
(where the script crashes in the middle part and the lock file stays
around even tho the job is dead).
Michael
More information about the Linux-users
mailing list