#!/bin/bash
fan_pin=14
stop_fan() {
gpioset --mode=signal pinctrl-bcm2711 $fan_pin=0 > /dev/null 2>&1 &
}
start_fan() {
# echo "debug: 进程号是$gpioset_pid"
kill -9 $gpioset_pid
}
while true;do
cputemp=`cat /sys/class/thermal/thermal_zone0/temp`
temp=$[ $cputemp/1000 ]
# echo "debug: 当前温度是$temp"
# 获取gpioset的进程号
gpioset_pid=`procs --only PID --no-header "gpioset --mode=signal pinctrl-bcm2711 $fan_pin=0"`
# 温度大于X度开启风扇
if [[ $temp -ge 60 && -n $gpioset_pid ]];then
# echo "debug: turning on the fan."
start_fan
fi
# 温度小于X度关闭风扇
if [[ $temp < 50 && -z $gpioset_pid ]];then
# echo "debug: turning off the fan."
stop_fan
fi
sleep 4
done
之后再配置个 cron 就可以了
@reboot /home/xiaobang/autoscript/casefan.sh