If I had to synchronize multiple scripts, I think I would stop thinking about 
shell scripting.  The noclobber thing is bash specific, and most unix 
distributions you see in the real world will not have bash, but instead they 
all have korn shell.  Korn shell is considered the de facto standard.  Unless, 
bash gets installed manually, which is generally frowned upon in places where 
standard builds and standard configurations are more important than the user's 
preference.  I would suggest using something like perl.  Every unix machine I 
have ever seen in any setting in my experience has perl.  

Of course, if you are stuck supporting an existing system and you cannot change 
it, then good luck. 

-Michael

----- Original Message ----
From: Bart Whiteley <[EMAIL PROTECTED]>
To: Provo Linux Users Group Mailing List <[email protected]>
Sent: Monday, February 12, 2007 2:20:03 PM
Subject: Re: synchronizing concurrent shell scripts

On 2/12/07, Michael L Torrie <[EMAIL PROTECTED]> wrote:
>
> >
> > However, touch works well.  Something like this has always worked for
> me.
> >
> > while [ -d /var/somelockfile ]; do sleep 1; done
> > touch /var/somelockfile
> > # do something
> > rm /var/somelockfile
>
> Sadly this will not work, at least if you goal is to synchronize
> multiple scripts running asynchronously.  It would have worked in my
> case, but it's not a semaphore.  Who wins when several processes make it
> past the while loop at about the same time?
>
>

Right.  This is why you should use the redirect '>' with noclobber instead.
With noclobber, the redirect works like an atomic test-and-set.

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/




/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to