dotlockfile
Bill Campbell
linux-sxs
Tue Jul 24 17:04:11 PDT 2007
On Tue, Jul 24, 2007, Michael Hipp wrote:
>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.
There's the perl LockFile::Simple module, and probably a python
equivalent.
The code for shlock is available in the inn news distribution,
and easy enough to compile outside of it.
Bill
--
INTERNET: bill at celestial.com Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676
There are three kinds of men. The ones that learn by reading. The few who
learn by observation. The rest of them have to pee on the electric fence
for themselves. -- Will Rogers
More information about the Linux-users
mailing list