-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfan-ctl.sh
executable file
·27 lines (24 loc) · 1.04 KB
/
fan-ctl.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
#!/bin/bash
mintemp=49000 # fan shutoff temp in millidegrees celcius
minpwm=50 # lowest desired pwm value
temprange=$((71000 - $mintemp)) # max temp - min temp in millidegrees celcius
pwmrange=$((255 - $minpwm)) # max PMW - min PWM. 0 to 255
cputherm=/sys/class/thermal/thermal_zone0/temp # thermometer readout (le potato max is 70C)
count=0
while [ $count -lt 100 ]; do
ffl="/sys/class/hwmon/hwmon"$count"/pwm1"
if test -f $ffl; then
fanpwm=$ffl # fan pwm writeout
break
fi
(( $count++ ))
done
while true; do # main loop
curtemp=$(cat $cputherm)
if [[ $curtemp -ge $mintemp ]]; then # if current temp is greater than minimum
echo $((($curtemp - $mintemp) * $pwmrange / $temprange + $minpwm)) | sudo tee $fanpwm
else
echo 0 | sudo tee $fanpwm # else shut off fan
fi
sleep 6 # wait 6 seconds
done