2015-05-11 00:25:31 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
url=http://10.2.113.137
|
|
|
|
run_file="/var/run/phone_ringing_status"
|
|
|
|
pidor=root@10.2.113.2
|
|
|
|
old_status=0
|
|
|
|
new_status=0
|
2015-05-11 22:50:29 +02:00
|
|
|
cd $(dirname "$0")
|
|
|
|
|
|
|
|
|
2015-05-11 00:25:31 +02:00
|
|
|
while true # empty pipe
|
|
|
|
do
|
|
|
|
sleep 1
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
read -t 1 status <&"${COPROC[0]}"
|
|
|
|
ret=$?
|
|
|
|
if [ $ret -eq 1 ] # no more coprocess
|
|
|
|
then
|
2016-03-24 23:33:11 +01:00
|
|
|
logger $0 "connecting to pidor"
|
2015-05-11 00:25:31 +02:00
|
|
|
coproc ssh -i ~/.ssh/doorbuzz $pidor
|
|
|
|
sleep 10
|
2016-03-24 23:33:11 +01:00
|
|
|
logger $0 "connected"
|
2015-05-11 00:25:31 +02:00
|
|
|
echo "flashoff" >&"${COPROC[1]}"
|
|
|
|
ret=0
|
|
|
|
fi
|
|
|
|
if [ $ret -ne 0 ]
|
|
|
|
then
|
|
|
|
break
|
|
|
|
fi
|
2016-03-24 23:33:11 +01:00
|
|
|
logger $0 "$status"
|
2015-05-11 00:25:31 +02:00
|
|
|
done
|
2016-03-31 20:43:28 +02:00
|
|
|
ocounter="$counter"
|
|
|
|
echo "peoplecounter" >&"${COPROC[1]}"
|
|
|
|
read counter <&"${COPROC[0]}"
|
|
|
|
if [ "$counter" != "$ocounter" ]
|
|
|
|
then
|
|
|
|
logger $0 peoplecounter=$counter
|
|
|
|
echo "neocounter=$counter" | ./redi.sh
|
|
|
|
fi
|
2015-05-11 00:25:31 +02:00
|
|
|
echo "spacestatus" >&"${COPROC[1]}"
|
|
|
|
read status <&"${COPROC[0]}"
|
|
|
|
if ! [ "$status" = "open" ]; then # do nothing if space is closed
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
# if ! [ -e "$run_file" ]; then
|
|
|
|
# touch $run_file
|
|
|
|
# fi
|
|
|
|
|
|
|
|
curl -q "$url" 2>/dev/null | grep Ringing
|
|
|
|
new_status=$?
|
|
|
|
# old_status=$(cat ${run_file})
|
|
|
|
|
|
|
|
if [ "$new_status" -eq "$old_status" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2016-03-24 23:33:11 +01:00
|
|
|
logger $0 "phone status change detected"
|
2015-05-11 00:25:31 +02:00
|
|
|
if [ "$new_status" -eq 0 ]; then
|
2015-05-11 22:50:29 +02:00
|
|
|
echo "neoaction=flash" | ./redi.sh
|
2015-05-11 00:25:31 +02:00
|
|
|
echo "flashon" >&"${COPROC[1]}"
|
|
|
|
else
|
2015-05-11 22:50:29 +02:00
|
|
|
echo "neoaction=pulse" | ./redi.sh
|
2015-05-11 00:25:31 +02:00
|
|
|
echo "flashoff" >&"${COPROC[1]}"
|
|
|
|
fi
|
|
|
|
# echo $new_status > ${run_file}
|
|
|
|
old_status=$new_status
|
|
|
|
fi
|
|
|
|
done
|