So add a check for the lock file at the begging of your script.  Better 
yet, if the lock file contained a timestamp, you could determine if the 
usual timeout periods have been exceeded and then just remove it.  Or 
even just use the last modified date of the file?

But I'm sure there's a better way... :)

Shawn

Nick Wiltshire wrote:
> On Friday 27 July 2007 13:33, John Greep wrote:
>> You can do simple locking by touching a file for the first instance and
>> checking for it in other instances.  In pseudo code:
>>
>> while .lock exists
>>  do nothing or wait a bit
>> end while
>> touch .lock
>> modify text file
>> delete .lock
> 
> But if a script dies before the delete, you've created an infinite queue.
> 
>> Roy Souther wrote:
>>> Is there anyway to do file locking in a bash script? I need to remove
>>> the race hazard from a script that has multiple running instances per
>>> user, each trying to make changes to a text file. I need to get
>>> exclusive access to a file and make the other instances wait their turn.
>>>
>>> Any ideas? Flock is supported by more advances script engines like
>>> Perl but flock seems to be beyond the ability of a simple shell like
>>> bash.
>>>
>>> _Royce Souther <mailto:[EMAIL PROTECTED]>_
>>> _www.SiliconTao.com <http://www.SiliconTao.com>_
>>> Let Open Source help your business move beyond.
>>>
>>> For security this message is digitally authenticated by _GnuPG
>>> <http://www.gnupg.org>_.
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> clug-talk mailing list
>>> [email protected]
>>> http://clug.ca/mailman/listinfo/clug-talk_clug.ca
>>> Mailing List Guidelines (http://clug.ca/ml_guidelines.php)
>>> **Please remove these lines when replying
>> _______________________________________________
>> clug-talk mailing list
>> [email protected]
>> http://clug.ca/mailman/listinfo/clug-talk_clug.ca
>> Mailing List Guidelines (http://clug.ca/ml_guidelines.php)
>> **Please remove these lines when replying
> 
> _______________________________________________
> clug-talk mailing list
> [email protected]
> http://clug.ca/mailman/listinfo/clug-talk_clug.ca
> Mailing List Guidelines (http://clug.ca/ml_guidelines.php)
> **Please remove these lines when replying

_______________________________________________
clug-talk mailing list
[email protected]
http://clug.ca/mailman/listinfo/clug-talk_clug.ca
Mailing List Guidelines (http://clug.ca/ml_guidelines.php)
**Please remove these lines when replying

Reply via email to