-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathfan_control_dyn.sh
84 lines (63 loc) · 1.79 KB
/
fan_control_dyn.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
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# Variables
IDRAC_IP="IP address of iDRAC"
IDRAC_USER="user"
IDRAC_PASSWORD="passowrd"
INTERVAL_SEC=5
INITIAL_START_DELAY_SEC=60
TEMP_THRESHOLD=35
TEMP_SENSOR="04h" # Inlet Temp
#TEMP_SENSOR="01h" # Exhaust Temp
#TEMP_SENSOR="0Eh" # CPU 1 Temp
#TEMP_SENSOR="0Fh" # CPU 2 Temp
FCTRL=0 #disabled, enabled=1
LAST_PCT=0
toggle() {
ipmitool -I lanplus -H $IDRAC_IP -U $IDRAC_USER -P $IDRAC_PASSWORD raw 0x30 0x30 0x01 $1 2>&1 >/dev/null
}
reset_manual() {
toggle 0x01
FCTRL=0 #disabled
}
set_manual() {
toggle 0x00
FCTRL=1 #enabled
}
graceful_exit() {
reset_manual
exit 0
}
trap graceful_exit SIGINT SIGTERM
# need the reset in case the system boots up with the last set value
reset_manual
#start delay
sleep $INITIAL_START_DELAY_SEC
while [ 1 ]
do
# Get temperature from iDARC.
T=$(ipmitool -I lanplus -H $IDRAC_IP -U $IDRAC_USER -P $IDRAC_PASSWORD sdr type temperature 2>/dev/null | grep $TEMP_SENSOR | cut -d"|" -f5 | cut -d" " -f2)
# If ambient temperature is above 35deg C enable dynamic control and exit, if below set manual control.
if [[ $T -ge $TEMP_THRESHOLD ]]
then
if [[ $FCTRL -ne 0 ]]
then
reset_manual
fi
else
# This gives a Percent that is a multiple of 5 for ranges of 5 degC
PCT=$(( 5 * ( T / 5 ) ))
# Min PCT Allowed is 10
PCT=$(( PCT < 10 ? 10 : PCT ))
if [[ $LAST_PCT -ne $PCT ]]
then
if [[ $FCTRL -eq 0 ]]
then
set_manual
fi
PCTHEX=$(printf '0x%02x' $PCT)
ipmitool -I lanplus -H $IDRAC_IP -U $IDRAC_USER -P $IDRAC_PASSWORD raw 0x30 0x30 0x02 0xff $PCTHEX 2>&1 >/dev/null
LAST_PCT=$PCT
fi
fi
sleep $INTERVAL_SEC
done