Skip to content

Instantly share code, notes, and snippets.

@gray
Created February 16, 2010 21:47
Show Gist options
  • Save gray/305973 to your computer and use it in GitHub Desktop.
Save gray/305973 to your computer and use it in GitHub Desktop.
ensure single running instance of a shell script
if command -v flock > /dev/null 2>&1; then
flock -nx "$LOCK" || exit
else
trap 'rm -f "$LOCK"; exit' INT QUIT TERM
shlock -f "$LOCK" -p $$ || exit
trap 'rm -f "$LOCK"; exit' EXIT
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment