Skip to content

Instantly share code, notes, and snippets.

@navels
Last active January 13, 2023 18:02
Show Gist options
  • Save navels/a267088726108fbf41b7e77a47822b21 to your computer and use it in GitHub Desktop.
Save navels/a267088726108fbf41b7e77a47822b21 to your computer and use it in GitHub Desktop.
ensure script is only run once at a time
# when sourced from another script, causes that script to be run at most once concurrently
if [[ $BASH_VERSION ]]; then
script=$(realpath ${BASH_SOURCE[1]})
else
script=$(realpath ${funcfiletrace[1]%:*})
fi
[[ $FLOCKER ]] || exec env FLOCKER="$script" flock -en "$script" "$script" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment