-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathon-off.sh
executable file
·53 lines (41 loc) · 1.05 KB
/
on-off.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
#!/bin/bash
MODE=on
if [ "x$1" = "xoff" ]; then
MODE=off
fi
RUNDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#config
source $RUNDIR/config.sh
DEBUG= #echo
declare -A TYPES
TYPES[intrusion]='Smart/FieldDetection/1'
TYPES[line]='Smart/LineDetection/1'
TYPES[motion]='System/Video/inputs/channels/1/motionDetection'
TYPES[pir]='WLAlarm/PIR'
SUCCESS=0
CNT=0
cd $RUNDIR
for cam in $CAMERAS; do
for type in "${!TYPES[@]}"; do
cmd=cameras/$cam/$type-$MODE.xml
if [ -f $cmd ]; then
#echo $cam-$type
$DEBUG curl -s --digest --user $USER:$PASS -T $cmd http://$cam/ISAPI/${TYPES[$type]} > response.xml
grep -q '<statusString>OK</statusString>' response.xml
if [ $? -ne 0 ]; then
SUCCESS=1
echo Failed $cam-$type
cat response.xml 1>&2
else
let CNT=$CNT+1
fi
fi
done
done
rm response.xml
if [ $SUCCESS -eq 0 ]; then
echo $MODE - $CNT - OK
else
echo $MODE - $CNT - NOK
fi
exit $SUCCESS