-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathilofancontrol
More file actions
145 lines (109 loc) · 2.79 KB
/
ilofancontrol
File metadata and controls
145 lines (109 loc) · 2.79 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
#
ILOIP="192.168.1.3"
USERNAME="fan"
PASSWORD='topsecret'
WAIT=3
if ! test "$1" = ""
then
LOG=1
else
LOG=0
fi
#
# Default Settings
#
# Temp in celsius
MINTEMP=40
MAXTEMP=90
# Fan in percentage
MINFAN=18
MAXFAN=99
STEP=5
LP=/var/run/fastfan
ALLFANS="0 1 2 3 4 5 6"
while :
do
echo
#
# Fetch CPU temperature
#
TEMP=0
N=0
if test $LOG -eq 1; then echo "Load: $(cat /proc/loadavg | awk '{print $1, $2}' ) "; fi
while test -e /sys/class/thermal/thermal_zone$N/temp
do
T1=$(echo "scale=0;$(cat /sys/class/thermal/thermal_zone$N/temp)/1000" | bc -l)
if test $LOG -eq 1; then echo "CPU temp: $T1"; fi
if test $T1 -gt $TEMP
then
TEMP=$T1
fi
let N=$N+1
done
#
# Fetch NVIDIA GPU temperature
#
if ! test "$(which nvidia-smi)" = ""
then
if test "$(nvidia-smi 2>&1 | grep failed)" = ""
then
while read GPUTEMP
do
if test $LOG -eq 1; then echo "GPU temp: $GPUTEMP"; fi
if test $GPUTEMP -gt $TEMP
then
let TEMP=GPUTEMP
fi
done < <(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader)
else
echo "Cannot load nvidia driver"
fi
fi
if test $LOG -eq 1; then echo "TOP temp: $TEMP"; fi
#
if test $TEMP -gt $MAXTEMP
then
TEMP=$MAXTEMP
fi
if test $TEMP -lt $MINTEMP
then
TEMP=$MINTEMP
fi
#
# Calculation of percentage fan performance
#
#echo " $MINFAN + ( ($TEMP - $MINTEMP) * ( ($MAXFAN - $MINFAN) / ($MAXTEMP - $MINTEMP) ) "
let W0=$(echo "scale=0;$TEMP-$MINTEMP"| bc -l)
let W1=$(echo "scale=0;$MAXFAN-$MINFAN" | bc -l)
let W2=$(echo "scale=0;$MAXTEMP-$MINTEMP" | bc -l)
let W4=$(echo "scale=0;$W0*$W1/$W2"| bc -l)
FAN=$(echo "scale=0;$MINFAN+$W4 " | bc -l)
if test $LOG -eq 1; then echo "Cal $FAN %"; echo; fi
#
# Kind of cache for fan control
#
if ! test -e $LP
then
echo "1" > $LP
fi
LASTFAN=$(cat $LP)
TD=$(echo "scale=0; $FAN - $LASTFAN " | bc -l)
if test $TD -lt 0
then
TD=$(echo "scale=0; -1 * $TD " | bc -l)
fi
if test $TD -gt $STEP
then
if test $LOG -eq 1; then echo "Setting $FAN to $ALLFANS"; fi
echo "$FAN" > $LP
FAN=$(echo "scale=0;254*$FAN/100" | bc -l)
if test $LOG -eq 1; then echo "Cal Setting values $FAN"; fi
for I in $ALLFANS
do
sshpass -p "$PASSWORD" ssh -oKexAlgorithms=+diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 -oHostKeyAlgorithms=ssh-rsa,ssh-dss $USERNAME@$ILOIP "fan p $I min $FAN" > /dev/null
done
fi
sleep $WAIT
done
exit 0