diff options
author | Calvin Morrison <mutantturkey@gmail.com> | 2014-04-10 11:16:07 -0400 |
---|---|---|
committer | Calvin Morrison <mutantturkey@gmail.com> | 2014-04-10 11:16:07 -0400 |
commit | 01dbecb2e93aa782685c87021a1bc6912b810c4d (patch) | |
tree | 753691167f8be6c93e073a57d7ad34289a32bf5b /lock.sh | |
parent | 15b51380182f13ca401d7ab9c39ab3ef5435de1b (diff) |
c version of lock
Diffstat (limited to 'lock.sh')
-rwxr-xr-x | lock.sh | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -0,0 +1,28 @@ +lock() { + + if [[ -f "$1" ]]; then + echo "$1 is not a lock directory." + exit 1 + fi + + if mkdir "$1" &>/dev/null; then + echo "lock $1 created" >&2 + else + echo "lock $1 found, waiting for unlock" >&2 + while true; do + sleep 2; + if [[ ! -d "$1" ]]; then + return + fi + done + fi; + +} + +if [[ "$#" -eq "1" ]]; then + lock "$1" +else + echo "please supply one argument: the lock directory." + exit 1 +fi + |