2023年12月13日发(作者:)

shell脚本-------查看cpu温度---

#!/bin/bash

#

功能:查看主板上单个多核

CPU

中温度最高的一个内核

#

脚本依赖:

lm_sensors

工具,可以执行下面语句进行安装,如果安装不了请更换

YUM

#

工具安装命令:

yum install -y lm_sensors

#

注意事项:

# 1.“sensors coretemp-isa-0000”

中后面的参数视主机实际的参数而定

# 2.

目前

vmware

虚拟机中

lm_sensors

工具无法查看硬件温度

CPU0=`sensors coretemp-isa-0000 | tail -n +3 |tr -s " " |awk -F [°C+] '{print $1$3}'`

CPU1=`sensors coretemp-isa-0004 | tail -n +3 |tr -s " " |awk -F [°C+] '{print $1$3}'`

function cpu0 {

max0=0.0

for i in $CPU0;do

if [ ${i%.*} -gt ${max0%.*} ];then

max0=$i

fi

done

echo $max0

}

function cpu1 {

max1=0.0

for j in $CPU1;do

if [ ${j%.*} -gt ${max1%.*} ];then

max1=$j

fi

done

echo $max1

}

$1