Skip to content

Instantly share code, notes, and snippets.

@naderio
Last active October 13, 2015 22:18
Show Gist options
  • Save naderio/4264511 to your computer and use it in GitHub Desktop.
Save naderio/4264511 to your computer and use it in GitHub Desktop.
Bash script file-based lock
#!/bin/bash
LOCK='path/to/file.lock'
[ -f "$LOCK" ] && { echo 'locked' >&2; exit 1; } || { touch "$LOCK" && trap 'rm -f "$LOCK"; exit $?' INT TERM EXIT; } || { echo 'unable to lock' >&2; exit 2; }
# processing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment