搞了个台式机,好久没碰物理设备了…天气较热,就做了下相关的搜索,除了安装一些辅助工具的办法,系统其实原生提供了接口
getTemp () {
for zone in `ls /sys/class/thermal/ | grep thermal_zone`
do
echo -n "`cat /sys/class/thermal/$zone/type`: "
echo `cat /sys/class/thermal/$zone/temp | sed 's/\(.\)..$/.\1°C/'`
done
}
另外,注意到温度还有一点是因为 Ubuntu (22.04) 登录时会在 motd 上显示。Ubuntu MOTD 的配置位于 /etc/update-motd.d/
。温度信息的来源是:
- /etc/update-motd.d/50-landscape-sysinfo
- /usr/bin/landscape-sysinfo (package: landscape-common)
- /usr/lib/python3/dist-packages/landscape/sysinfo/temperature.py
- /usr/lib/python3/dist-packages/landscape/lib/sysstats.py
参考:
- https://askubuntu.com/questions/15832/how-do-i-get-the-cpu-temperature/1131448#1131448
- https://blog.kavinyao.com/posts/ubuntu-motd-temp/
- https://askubuntu.com/questions/1110943/what-do-the-different-thermal-zones-actually-correspond-to/1339370#1339370
- https://github.com/intel/ioc-cbc-tools/blob/master/cbc_thermal/README.md#thermal-daemon