Last active
September 9, 2020 21:02
-
-
Save ricsiga/cecb5936e2c254133f6c5522a5581cc1 to your computer and use it in GitHub Desktop.
BASH lock file example
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
#!/usr/bin/env bash | |
set -e | |
lockFile="/var/tmp/app.lock" | |
if ( set -o noclobber; echo "locked" > "$lockFile") 2> /dev/null; then | |
trap 'rm -f "$lockFile"; exit $?' INT TERM EXIT | |
else | |
echo "Can't get file lock, $(basename "$0") already running" >&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment