Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!sgi!shinobu!odin!thestepchild!rhartman From: rhartman@thestepchild.sgi.com (Robert Hartman) Newsgroups: comp.unix.shell Subject: Re: Creating a lock file in sh? Message-ID: <1991Apr17.201931.14536@odin.corp.sgi.com> Date: 17 Apr 91 20:19:31 GMT References: Sender: news@odin.corp.sgi.com (Net News) Distribution: na Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 24 In article pablo@sgi.com (Pablo Sanchez) writes: >Hey there, > > I apologize if this has been hashed over a bizzillion times but can >someone please send me their Bourne-shell lock-file implementation. >Thanks. Aside from the fact that it isn't guaranteed over NFS, you can get some measure of protection this way: if [ ! -w $file.lock ] ; then echo $user: $$ `date` > $file.lock if [ $$ -eq `awk '{print $2}' $file.lock` ] ; then # enter protected section # ... # exit protected section else echo "$file in use" ; exit 1 fi else echo "$file in use" ; exit 1 fi -r