-
Notifications
You must be signed in to change notification settings - Fork 11
/
discovery.sensor
executable file
·42 lines (39 loc) · 1.08 KB
/
discovery.sensor
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
#!/bin/bash
SENSORS="/usr/bin/sensors"
EGREP="/bin/egrep"
TR="/usr/bin/tr"
CUT="/usr/bin/cut"
/bin/cat << END
{
"data":[
END
JSONHACK=""
for chip in $($SENSORS -u 2>/dev/null|$EGREP "^[^:]+$")
do
while read sensor
do
case $sensor in
temp*)
UNITS="°C"
;;
power*)
UNITS="W"
;;
in*)
UNITS="V"
;;
fan*)
UNITS="RPM"
;;
*)
UNITS=""
;;
esac
/bin/echo -e "\t\t{\"{#CHIP}\":\"$chip\", \"{#SENSOR}\":\"$sensor\", \"{#UNITS}\":\"$UNITS\"}$JSONHACK"
JSONHACK=","
done <<<"$($SENSORS -u $chip 2>/dev/null|$EGREP "_input:"|$TR -d " "|$CUT -d_ -f1)"
done|tac
/bin/cat << END
]
}
END