Add lock script

master
madmaurice 5 years ago committed by Hive
parent 1e2b15036a
commit c4f09a98dc
  1. 46
      lock.sh

@ -0,0 +1,46 @@
#!/bin/bash
LOCKDIR="/tmp/snapshotslocks/"
[ ! -d "$LOCKDIR" ] && mkdir -p "$LOCKDIR"
createlock() {
LOCKNAME=$1
[ -f "$LOCKDIR/$LOCKNAME.lock" ] && exit 1
touch "$LOCKDIR/$LOCKNAME.lock"
exit 0
}
deletelock() {
LOCKNAME=$1
[ ! -f "$LOCKDIR/$LOCKNAME.lock" ] && exit 1
rm "$LOCKDIR/$LOCKNAME.lock"
exit 0
}
haslock() {
if ls $LOCKDIR/* 1> /dev/null 2>&1; then
exit 0
else
exit 1
fi
}
case $1 in
lock)
createlock $2
;;
unlock)
deletelock $2
;;
haslock)
haslock
;;
show)
ls $LOCKDIR
;;
*)
echo "What is $1" >&2
exit 1
esac
Loading…
Cancel
Save