文章8
标签0
分类4

为我家云,粒子云添加自动风扇及关机功能。

#复制以下代码使用root权限粘贴到ssh中。 
#!/bin/bash
cat <<\EOF >/lib/systemd/system-shutdown/lenovo
#!/bin/bash
if [[ $1 = "halt" || $1 = "poweroff" ]]; then
sync
hdparm -y /dev/sda
hdparm -y /dev/sdb
hdparm -y /dev/sdc
sleep 5
echo 102 > /sys/class/gpio/export
echo high > /sys/class/gpio/gpio102/direction
fi
EOF
cat <<\EOF >/lib/systemd/system/fan.service
[Unit]
Description=The PWM fan Script
After=syslog.target

[Service]
Type=forking
PIDFile=/var/run/fan.pid
ExecStart=/bin/bash -c "/sbin/fan "&
ExecReload=/bin/kill -s HUP
ExecStop=/bin/kill -s QUIT
PrivateTmp=true

[Install]
WantedBy=multi-user.target

EOF

cat <<\EOF >/sbin/fan

#!/bin/bash
echo $ > /var/run/fan.pid

echo 85 > /sys/class/gpio/export
echo "high" > /sys/class/gpio/gpio85/direction
echo 85 > /sys/class/gpio/unexport

echo 79 > /sys/class/gpio/export
echo high > /sys/class/gpio/gpio79/direction
echo 0 > /sys/class/pwm/pwmchip0/export
echo 10000 > /sys/class/pwm/pwmchip0/pwm0/period
echo normal > /sys/class/pwm/pwmchip0/pwm0/polarity
echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable

while true
do
        temp=$(cat /sys/class/thermal/thermal_zone0/temp)
        if [ $temp -gt 75000 ]; then
                echo 10000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle;
        elif  [ $temp -gt 65000 ]; then
                echo 6000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle;
        elif  [ $temp -gt 55000 ]; then
                echo 2000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle;
        else
                echo 0 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle;
        fi
        sleep 10
done

EOF
chmod +x /sbin/fan
systemctl enable fan.service
systemctl start fan.service

1 评论

  1. 熊先生 5月7日 回复
    风扇无法停止