dotlockfile
Michael Hipp
Michael
Tue Jul 24 15:47:19 PDT 2007
Lonni J Friedman wrote:
> On 7/24/07, Michael Hipp <Michael at hipp.com> wrote:
>> 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).
>
> So add a grep ps output for the process name of whatever it is you're
> running (or more than one instance (pipe it to 'wc -l', if the concern
> is running multiples concurrently).
>
> I guess i don't understand the obstacle. Is it that you aren't sure
> how to implement this, or something else?
I just believe in the concept of not reinventing the wheel. Figured
someone else had already done it and could share a few stanzas of script
code. That's kinda what we're about here, isn't it?
Oddly enough, I've found a plethora of bash scripting websites that talk
about lock files but none of them handle the "what ifs" very well. Odd.
Michael
More information about the Linux-users
mailing list