-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhardwarewatch.sh
More file actions
executable file
·81 lines (61 loc) · 2.95 KB
/
hardwarewatch.sh
File metadata and controls
executable file
·81 lines (61 loc) · 2.95 KB
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
73
74
75
76
77
78
79
80
#!/bin/bash
source /home/pi/cid.config
status=$(lsusb | grep 072f:2200 | wc -l)
upseconds=$(cat /proc/uptime | grep -o '^[0-9]\+')
dmesgwatch=$(dmesg | grep disconnect | wc -l)
DATE="`date +%s`000"
NAME=$(hostname)
LOGSPACE=$(df -k /tmp/ |grep tmpfs| awk -v col=4 '{print $col}')
READERDETECT=$(dmesg | grep "New USB device found, idVendor=072f, idProduct=2200" | wc -l)
PREVREADER=$(cat /tmp/READERDETECT)
JAVASTATUS=$(jps -l | wc -l)
KEYBOARDDETECT=$(lsusb -v | grep -i key |wc -l)
uptime=$(</proc/uptime)
uptime=${uptime%%.*}
seconds=$(( uptime%60 ))
minutes=$(( uptime/60%60 ))
hours=$(( uptime/60/60%24 ))
days=$(( uptime/60/60/24 ))
## tell the monitoring server how long we've been up
curl -X POST -d "cid=${key}&host=${name}&level=FINER&type=LOG&date=${DATE}&message=uptime is ${days} days, ${hours} hours, ${minutes} minutes, ${seconds} seconds" "http://cidmonitor.lodgon.com/pimonitor/rest/monitor/log"
echo $key
echo $secret
#curl -X POST -d "cid=${key}&host=${name}&level=INFO&type=LOG&date=${DATE}&message=hardware looks OK" "http://cidmonitor.lodgon.com/pimonitor/rest/m$
##make sure this script does not run before the hardware has a chance to settle
if [ $upseconds -le 60 ]
then
echo "up for less than 1 min"
exit 0
fi
#check if the cardreader is present
if [ $status -ne 1 ]
then
echo "no usb reader detected"
curl -X POST -d "cid=${key}&host=${name}&level=SEVERE&type=LOG&date=${DATE}&message=NO NFC reader connected" "http://cidmonitor.lodgon.com/pimonitor/rest/monitor/log"
fi
##detect disconnections of the Usb reader
if (($READERDETECT > $PREVREADER))
then
echo "usb cardreader detected multiple times "
echo $READERDETECT > /tmp/READERDETECT
curl -X POST -d "cid=${key}&host=${name}&level=SEVERE&type=LOG&date=${DATE}&message=NFC reader disconnected and reconnected" "http://cidmonitor.lodgon.com/pimonitor/rest/monitor/log"
fi
##empty the logfile if the space on the tmp partitie is growing small
if [ $LOGSPACE -le 1028 ]
then
echo > /tmp/cid.log
fi
## check if the java app is running
if [ $JAVASTATUS -le 1 ]
then
if [ $KEYBOARDDETECT -ge 2 ]
then
curl -X POST -d "cid=${key}&host=${name}&level=SEVERE&type=LOG&date=${DATE}&message=java app not STARTED, keyboard detected" "http://cidmonitor.lodgon.com/pimonitor/rest/monitor/log"
else
curl -X POST -d "cid=${key}&host=${name}&level=SEVERE&type=LOG&date=${DATE}&message=JAVA app not running, trying to restart" "http://cidmonitor.lodgon.com/pimonitor/rest/monitor/log"
echo "trying to restart only java apps" | wall
killall java
sleep 5
/home/pi/run.sh
fi
fi