Skip to content

Instantly share code, notes, and snippets.

@ricsiga
Last active September 9, 2020 21:02
Show Gist options
  • Save ricsiga/cecb5936e2c254133f6c5522a5581cc1 to your computer and use it in GitHub Desktop.
Save ricsiga/cecb5936e2c254133f6c5522a5581cc1 to your computer and use it in GitHub Desktop.
BASH lock file example
#!/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