Skip to main content
Tweeted twitter.com/#!/StackUnix/status/240192120437239808
edited tags
Link
jw013
  • 53k
  • 11
  • 143
  • 142
Source Link
9000
  • 1.7k
  • 2
  • 14
  • 23

Locking in a shell script

I want to write a long-running shell script so that only one copy could be run at a time. If the script crashes, I want a new invocation of the script not to be stopped by a lock from the crashed invocation.

Is lockfile-* set of utils the right thing to use? Is there a chance of a race condition while using them in a script?

Does --use-pid lift the 5-minutes limitation mentioned on the man page? My scripts run significantly longer.

I use an Ubuntu 10.10 instance on Amazon EC2; no NFS or something like that.