dotlockfile
Lonni J Friedman
netllama
Tue Jul 24 15:19:29 PDT 2007
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?
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
L. Friedman netllama at gmail.com
LlamaLand http://netllama.linux-sxs.org
More information about the Linux-users
mailing list