Skip to content

Instantly share code, notes, and snippets.

@mpdroog
Created August 31, 2021 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpdroog/a91b4532230f6c7690b728113c86972c to your computer and use it in GitHub Desktop.
Save mpdroog/a91b4532230f6c7690b728113c86972c to your computer and use it in GitHub Desktop.
Ensure only one instance at the same time
#!/usr/bin/env bash
# Using lock-file to ensure only one instance can be running
# at the same time.
# DevNote: The trap is used to ensure we ALWAYS remove the lock upon completion
set -x
set -e
if ! mkdir /tmp/MYSCRIPT.lock; then
printf "MYSCRIPT already running.\n" >&2
exit 1
fi
trap 'rm -rf /tmp/MYSCRIPT.lock' EXIT
/path/to/original.file.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment