-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeedfans
89 lines (72 loc) · 1.3 KB
/
speedfans
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
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
IPMIHOST=192.168.1.100
IPMIUSER=operator
IPMIPW=1234
IPMIEK=0000000000000000000000000000000000000000
FANSPEEDHEX="0xA"
MAXTEMP=60
HYSTERESIS=5
INTERVAL=5
function ipmi() {
ipmitool -I lanplus -H "$IPMIHOST" -U "$IPMIUSER" -P "$IPMIPW" -y "$IPMIEK" "$@"
}
function auto_fans() {
ipmi raw 0x30 0x30 0x01 0x01
}
function manual_fans() {
ipmi raw 0x30 0x30 0x01 0x00
ipmi raw 0x30 0x30 0x02 0xff "$FANSPEEDHEX"
}
function emergency() {
# insert here what should happen when the sensor readings fail.
auto_fans
exit 1
}
function d_start() {
while sleep $INTERVAL
do
if ! TEMPS=$(ipmi sdr type temperature | grep -vi inlet | grep -vi exhaust | grep -Po '\d{2,3}' 2>&1); then
# Emergency
echo "problem with reading the temperature"
emergency
fi
HIGHTEMP=0
LOWTEMP=1
MSG="TEMPS"
for TEMP in $TEMPS; do
MSG+=" $TEMP"
if [[ $TEMP > $MAXTEMP ]]; then
HIGHTEMP=1
fi
if [[ $TEMP > $((MAXTEMP - HYSTERESIS)) ]]; then
LOWTEMP=0
fi
done
echo $MSG
if [[ $HIGHTEMP == 1 ]]; then
#Automatic fan control
auto_fans
elif [[ $LOWTEMP == 1 ]]; then
#Manual fan control
manual_fans
fi
done
}
function d_stop() {
emergency
}
case "$1" in
start)
d_start
;;
stop)
d_stop
;;
restart)
d_restart
;;
status)
d_status
;;
*)
esac