prevented multiple instances from starting within 15 seconds. only one action is allowed within 15 seconds.
This commit is contained in:
parent
b0eb760572
commit
b254666566
21
door.sh
21
door.sh
|
@ -6,24 +6,29 @@ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||||
OPEN_INDICATOR=/tmp/door_status_open
|
OPEN_INDICATOR=/tmp/door_status_open
|
||||||
CLOSED_INDICATOR=/tmp/door_status_closed
|
CLOSED_INDICATOR=/tmp/door_status_closed
|
||||||
|
|
||||||
|
if [ -f $OPEN_INDICATOR ]; then
|
||||||
|
LOCK_AGE=$(( $(date +%s)-$(stat -c %X $OPEN_INDICATOR) ))
|
||||||
|
elif [ -f $CLOSE_INDICATOR ]; then
|
||||||
|
LOCK_AGE=$(( $(date +%s)-$(stat -c %X $CLOSED_INDICATOR) ))
|
||||||
|
else
|
||||||
|
LOCK_AGE=15
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $LOCK_AGE -lt 15 ]; then
|
||||||
|
echo "please wait at least 15 seconds befor a second run of this script" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
./door_verify.sh
|
./door_verify.sh
|
||||||
STATUS=$?
|
STATUS=$?
|
||||||
if [ $STATUS -eq 0 ]; then
|
if [ $STATUS -eq 0 ]; then
|
||||||
echo "opening door"
|
echo "opening door"
|
||||||
if [ -f $OPEN_INDICATOR ]; then
|
if [ -f $OPEN_INDICATOR ]; then
|
||||||
if [ $(( $(date +%s)-$(stat -c %X $OPEN_INDICATOR) )) -lt 15 ]; then
|
|
||||||
echo "please wait at least 15 seconds befor a second run of this script" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "closing door"
|
echo "closing door"
|
||||||
./door_lock.sh close
|
./door_lock.sh close
|
||||||
rm $OPEN_INDICATOR
|
rm $OPEN_INDICATOR
|
||||||
touch $CLOSED_INDICATOR
|
touch $CLOSED_INDICATOR
|
||||||
else
|
else
|
||||||
if [ $(( $(date +%s)-$(stat -c %X $CLOSED_INDICATOR) )) -lt 15 ]; then
|
|
||||||
echo "please wait at least 15 seconds befor a second run of this script" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "opening door"
|
echo "opening door"
|
||||||
./door_lock.sh open
|
./door_lock.sh open
|
||||||
rm $CLOSED_INDICATOR
|
rm $CLOSED_INDICATOR
|
||||||
|
|
Loading…
Reference in New Issue