-
Notifications
You must be signed in to change notification settings - Fork 0
/
phone_notification_client.sh
executable file
·72 lines (67 loc) · 1.58 KB
/
phone_notification_client.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
url=http://10.2.113.137
run_file="/var/run/phone_ringing_status"
old_status=0
new_status=0
cd $(dirname "$0")
while true # empty pipe
do
sleep 1
while true
do
read -t 1 status <&"${COPROC[0]}" 2>/dev/null
ret=$?
if [ $ret -eq 1 ] # no more coprocess
then
logger $0 "connecting to pidor"
coproc ssh -i ~/.ssh/doorbuzz $pidor
sleep 10
logger $0 "connected"
echo "flashoff" >&"${COPROC[1]}"
ret=0
fi
if [ $ret -ne 0 ]
then
break
fi
logger $0 "$status"
done
ocounter="$counter"
echo "peoplecounter" >&"${COPROC[1]}"
read -t 1 counter <&"${COPROC[0]}"
if [ $? -ne 0 ]
then
counter=-1
fi
if [ "$counter" != "$ocounter" ]
then
logger $0 peoplecounter=$counter
echo "neocounter=$counter" | ./redi.sh
fi
echo "spacestatus" >&"${COPROC[1]}"
read -t 1 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
logger $0 "phone status change detected"
if [ "$new_status" -eq 0 ]; then
printf "neoaction=flash\nvalid=yes\n" | ./redi.sh
echo "flashon" >&"${COPROC[1]}"
else
printf "neoaction=pulse\nvalid=yes\n" | ./redi.sh
echo "flashoff" >&"${COPROC[1]}"
fi
# echo $new_status > ${run_file}
old_status=$new_status
fi
done