Add lock script
This commit is contained in:
parent
1e2b15036a
commit
c4f09a98dc
1 changed files with 46 additions and 0 deletions
46
lock.sh
Executable file
46
lock.sh
Executable file
|
@ -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…
Reference in a new issue