Skip to content

Instantly share code, notes, and snippets.

@darth-veitcher
Created September 10, 2021 08:36
Show Gist options
  • Save darth-veitcher/399a6795e2b240783691d194b415b7f8 to your computer and use it in GitHub Desktop.
Save darth-veitcher/399a6795e2b240783691d194b415b7f8 to your computer and use it in GitHub Desktop.
Using a lock file in a bash script
# Check is Lock File exists, if not create it and set trap on exit
if { set -C; 2>/dev/null >${LOCK_FILE}; }; then
trap "rm -f ${LOCK_FILE}" EXIT
else
echo "Lock file exists at ${LOCK_FILE}… exiting"
exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment