Created
September 24, 2015 20:14
-
-
Save dirkgr/1ab47c7d5864d9e9aabd to your computer and use it in GitHub Desktop.
How to lock in bash
This file contains 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
#!/usr/bin/env bash | |
set -e | |
set -x | |
LOCKFILE=~/LOCK | |
if [ $1 -a $1 = "lockAcquired" ]; then | |
echo "I'm in." | |
sleep 10 | |
else | |
echo "Acquiring lockfile $LOCKFILE ..." | |
flock $LOCKFILE $0 lockAcquired "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment