Last active
October 13, 2015 22:18
-
-
Save naderio/4264511 to your computer and use it in GitHub Desktop.
Bash script file-based lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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