I spent a long time looking for a Linux command line tool that would help synchronize backups around a semaphore… I didn’t implicitly trust the value of a touch /tmp/.dontdoanythingrightnow. I eventually found a good answer in the appropriately-named lockfile utility. It basically takes care of race conditions in scripts pretty handily. Run it, and if another process already has run lockfile on that semaphore, it sleeps for n number of minutes, waking up each minute to retry. On failure, it sets its return code so you can write up failure detection routines that don’t get tripped unless the previous procedure is taking longer than you planned.
http://www.die.net/doc/linux/man/man1/lockfile.1.html http://linux.about.com/library/cmd/blcmdl1_lockfile.htm
Pass along a number of minutes to delay, and you can devise some pretty trustworthy synchronized scripts in a difficult environment.