Created
October 17, 2014 11:00
-
-
Save blaxter/39a7e1363a1a537fbc3c to your computer and use it in GitHub Desktop.
script with lock
This file contains hidden or 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
lockfile=/var/tmp/mylock | |
if ( set -o noclobber; echo "$$" > "$lockfile") 2> /dev/null; then | |
trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT | |
# do stuff here | |
# clean up after yourself, and release your trap | |
rm -f "$lockfile" | |
trap - INT TERM EXIT | |
else | |
echo "Lock Exists: $lockfile owned by $(cat $lockfile)" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment