Core 1: +27.0°C (high = +83.0°C, crit = +93.0°C)
Core 2: +28.0°C (high = +83.0°C, crit = +93.0°C)
Core 3: +30.0°C (high = +83.0°C, crit = +93.0°C)
Core 4: +29.0°C (high = +83.0°C, crit = +93.0°C)
Core 5: +29.0°C (high = +83.0°C, crit = +93.0°C)
Core 8: +29.0°C (high = +83.0°C, crit = +93.0°C)
Core 9: +28.0°C (high = +83.0°C, crit = +93.0°C)
Core 10: +28.0°C (high = +83.0°C, crit = +93.0°C)
Core 11: +28.0°C (high = +83.0°C, crit = +93.0°C)
Core 12: +31.0°C (high = +83.0°C, crit = +93.0°C)
Core 13: +28.0°C (high = +83.0°C, crit = +93.0°C)
这条指令中tail -n +3表示显示文件从第3行至文件末尾的文件内容
[root@dana ~]# sensors coretemp-isa-0000 | tail -n +3 |tr -s " "
Package id 0: +33.0°C (high = +83.0°C, crit = +93.0°C)
Core 0: +32.0°C (high = +83.0°C, crit = +93.0°C)
Core 1: +29.0°C (high = +83.0°C, crit = +93.0°C)
Core 2: +28.0°C (high = +83.0°C, crit = +93.0°C)
Core 3: +32.0°C (high = +83.0°C, crit = +93.0°C)
Core 4: +30.0°C (high = +83.0°C, crit = +93.0°C)
Core 5: +30.0°C (high = +83.0°C, crit = +93.0°C)
Core 8: +30.0°C (high = +83.0°C, crit = +93.0°C)
Core 9: +29.0°C (high = +83.0°C, crit = +93.0°C)
Core 10: +28.0°C (high = +83.0°C, crit = +93.0°C)
Core 11: +29.0°C (high = +83.0°C, crit = +93.0°C)
Core 12: +31.0°C (high = +83.0°C, crit = +93.0°C)
Core 13: +29.0°C (high = +83.0°C, crit = +93.0°C)
这条指令中tr -s " “表示删除” ",可以理解为删除空格
[root@dana ~]# sensors coretemp-isa-0000 | tail -n +3 |tr -s " " |awk -F [°C+] ‘{print $0}’
Package id 0: +32.0°C (high = +83.0°C, crit = +93.0°C)
Core 0: +31.0°C (high = +83.0°C, crit = +93.0°C)
Core 1: +27.0°C (high = +83.0°C, crit = +93.0°C)
Core 2: +27.0°C (high = +83.0°C, crit = +93.0°C)
Core 3: +29.0°C (high = +83.0°C, crit = +93.0°C)
Core 4: +28.0°C (high = +83.0°C, crit = +93.0°C)
Core 5: +28.0°C (high = +83.0°C, crit = +93.0°C)
Core 8: +28.0°C (high = +83.0°C, crit = +93.0°C)
Core 9: +27.0°C (high = +83.0°C, crit = +93.0°C)
Core 10: +27.0°C (high = +83.0°C, crit = +93.0°C)
Core 11: +28.0°C (high = +83.0°C, crit = +93.0°C)
Core 12: +30.0°C (high = +83.0°C, crit = +93.0°C)
Core 13: +28.0°C (high = +83.0°C, crit = +93.0°C)
这条指令中awk -F [°C+] '{print $0}'表示按照°C+为指定分割符并输出每一行内容
[root@dana ~]# sensors coretemp-isa-0000 | tail -n +3 |tr -s " " |awk -F [°C+] ‘{print $1}’
Package id 0:
这条指令中{print $1}表示只输出每一行第1个字段内容
[root@dana ~]# sensors coretemp-isa-0000 | tail -n +3 |tr -s " " |awk -F [°C+] ‘{print $3}’
32.0
28.0
28.0
31.0
29.0
29.0
29.0
29.0
28.0
29.0
31.0
28.0
这条指令中{print $3}表示只输出每一行第3个字段内容
[root@dana ~]# sensors coretemp-isa-0000 | tail -n +3 |tr -s " " |awk -F [°C+] ‘{print $6}’
83.0
83.0
83.0
83.0
83.0
83.0
83.0
83.0
83.0
83.0
83.0
83.0
这条指令中{print $6}表示只输出每一行第6个字段内容
[root@dana ~]# sensors coretemp-isa-0000 | tail -n +3 |tr -s " " |awk -F [°C+] ‘{print $9}’
93.0
93.0
93.0
93.0
93.0
93.0
93.0
93.0
93.0
93.0
93.0
93.0
这条指令中{print $9}表示只输出每一行第9个字段内容
3 终极代码实现(放大招)
#!/bin/bash
# 功能:查看主板上单个多核CPU中温度最高的一个内核
# 脚本依赖:lm\_sensors工具,可以执行下面语句进行安装,如果安装不了请更换YUM源
# 工具安装命令:yum install -y lm\_sensors
# 注意事项:
# 1.“sensors coretemp-isa-0000”中后面的参数视主机实际的参数而定
# 2.目前vmware虚拟机中lm\_sensors工具无法查看硬件温度
date=`date "+%Y-%m-%d %H:%M:%S"`
echo $date
CPU0=`sensors coretemp-isa-0000 | tail -n +3 |tr -s " " |awk -F [°C+] '{print $3}'`
CPU1=`sensors coretemp-isa-0001 | tail -n +3 |tr -s " " |awk -F [°C+] '{print $3}'`
echo $CPU0
echo $CPU1
highCPU0=`sensors coretemp-isa-0000 | tail -n +3 |tr -s " " |awk -F [°C+] '{print $1$6}'`
highCPU1=`sensors coretemp-isa-0001 | tail -n +3 |tr -s " " |awk -F [°C+] '{print $1$6}'`
for i in $CPU0;
do
echo $i
#echo $i|awk '{printf("%d\n",$0);}'
#if [ $i -lt 83 ];then
if [ `echo "$i > 83.0"` ] ; then
echo "$date 请注意!!!coretemp-isa-0000 cpu温度为$i度,请及时排查">>/var/log/cpu_message
elif [ `echo "$i > 93.0"` ] ; then
echo "请注意!!!!!!coretemp-isa-0000 cpu超过此温度就会烧坏,请及时排查">>/var/log/cpu_message
else
echo "cpu运行一切正常"
fi
done
for j in $CPU1;
do
echo $i
#echo $i|awk '{printf("%d\n",$0);}'
#if [ $i -lt 83 ];then
if [ `echo "$j > 83.0"` ] ; then
echo "$date 请注意!!!coretemp-isa-0001 cpu温度为$i度,请及时排查">>/var/log/cpu_message
elif [ `echo "$j > 93.0"` ] ; then
echo "$date 请注意!!!!!!coretemp-isa-0001 cpu超过此温度就会烧坏,请及时排查">>/var/log/cpu_message
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/topics/618542503)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**