-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathxu4-fancontrol.sh
94 lines (82 loc) · 1.95 KB
/
xu4-fancontrol.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
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
REFRESH="1"
DISK_TEMP_THRESHOLD="45"
CPU_TEMP_THRESHOLD="60"
FAN_CHANGED="*"
get_disk_dev_info() {
# Pull disk info from /dev/sd*
fdisk -l > disks.txt 2>/dev/null
SATA=($(awk '/^\/dev\/sd/ {printf "%s ", $1}' disks.txt))
rm disks.txt
}
get_disk_temperature() {
for i in "${!SATA[@]}"
do
# declare and assign variable seperately to avoid masking return value
DISK_TEMP[$i]=" (IDLE)"
local t
t=$(smartctl -a "${SATA[$i]}" -d sat | grep "Temp")
if (( $? == 0 ))
then
local temp=$(echo $t | awk '{print $10}')
DISK_TEMP[$i]="$temp"
else
DISK_TEMP[$i]=""
fi
done
}
get_cpu_temperature() {
for i in {0..4}
do
_t=$(($(</sys/class/thermal/thermal_zone${i}/temp) / 1000))
CPU_TEMP[$i]="$_t"
done
}
fan_on() {
i2cset -y 1 0x60 0x05 0x00
}
fan_off() {
i2cset -y 1 0x60 0x05 0x05
}
handle_fan() {
for i in "${!DISK_TEMP[@]}"
do
if (( "${DISK_TEMP[$i]}" > "${DISK_TEMP_THRESHOLD}" ))
then
if [ "${FAN_CHANGED}" != "1" ]
then
echo "Turning fan on because disk $i has hit the threshold"
fi
FAN_CHANGED="1"
fan_on
return
fi
done
for i in "${!CPU_TEMP[@]}"
do
if (( "${CPU_TEMP[$i]}" > "${CPU_TEMP_THRESHOLD}" ))
then
if [ "${FAN_CHANGED}" != "1" ]
then
echo "Turning fan on because CPU $i has hit the threshold"
fi
FAN_CHANGED="1"
fan_on
return
fi
done
# No fuss, fan is off
if [ "${FAN_CHANGED}" != "0" ]
then
echo "All temps nominal, turning fan off"
FAN_CHANGED="0"
fi
fan_off
}
while true; do
get_disk_dev_info
get_disk_temperature
get_cpu_temperature
handle_fan
sleep ${REFRESH}
done