(原) 给家里的服务器加个温控风扇

原创文章,请后转载,并注明出处。

最近将家里弃用的平板电脑做成pve虚拟机发挥点余热。原来这台平板电脑就是个被动散热,做服务器热不得,一热就降频,还死机。
购买一个USB继电器,它模拟一个串口,通过发送指令让继电器开合。至于继电器之后,你可以随意发挥,这里就用来接小巧的USB风扇。

#!/bin/bash

# Set the threshold temperature in Celsius
threshold=80

# Get the current temperature in Celsius
temp=$(cat /sys/class/thermal/thermal_zone0/temp)
temp=$(($temp/1000))

# Compare the current temperature with the threshold
if [ $temp -gt $threshold ]; then
  echo -e -n "\xA0\x01\x01\xA2" > /dev/ttyUSB0
else
  echo -e -n "\xA0\x01\x00\xA1" > /dev/ttyUSB0
fi

把以上脚本放到定时任务中,例如每分钟运行一次。

除此之外,你还可以用脚本主动降频,方法如此文章中提到的设置CPU频率模式


sensors | grep ‘Core 1’ | awk ‘{print $3}’ | sed ’s/°C//g’ | sed ’s/+//g’ | cut -f1 -d"."

通过安装sensors,也可以获取到更多位置的温度。