0

Linux 下获取 CPU 温度

 1 year ago
source link: https://blog.shuf.io/post/how-to-get-cpu-temperature-in-linux
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Jul 02, 2022

Linux 下获取 CPU 温度

搞了个台式机,好久没碰物理设备了…天气较热,就做了下相关的搜索,除了安装一些辅助工具的办法,系统其实原生提供了接口

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

Some rights reserved

Except where otherwise noted, content on this page is licensed under a Creative Commons Attribution-NonCommercial 4.0 International license.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK