[CentOS] Lock files in scripts

Wed Jul 13 17:16:12 UTC 2011
Kenneth Porter <shiva at sewingwitch.com>

I was about to ask here how to do proper locking in a bash script when I 
found a page that addressed my objections to the race conditions I was 
finding in most sample code:

<http://www.davidpashley.com/articles/writing-robust-shell-scripts.html>

I just wanted to pass on the link to anyone else that needs this.

One thing not addressed is how to deal with an orphaned lock file (eg. if 
the system crashes with the lock held). He stores the PID in the lock file, 
so one could look up the matching process and see if it's the script that's 
expected to create it. Otherwise one should be safe in deleting the lock 
file and trying again.