synchronizing concurrent shell scripts
brailsmt at yahoo.com
Mon Feb 12 13:29:04 MST 2007
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.
----- Original Message ----
From: Bart Whiteley <bart.plug at whiteley.org>
To: Provo Linux Users Group Mailing List <plug at plug.org>
Sent: Monday, February 12, 2007 2:20:03 PM
Subject: Re: synchronizing concurrent shell scripts
On 2/12/07, Michael L Torrie <torriem at chem.byu.edu> wrote:
> > However, touch works well. Something like this has always worked for
> > 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
Don't fear the penguin.
More information about the PLUG