最近在整机压测过程中,发现最作为系统盘的m.2有温度过高的现象,所以在做这项测试过程中,需要我们同时也检测一下M.2的温度。下面开始编写这个小脚本。
1.首先获取系统盘的温度
[root@localhost Desktop]# smartctl -a /dev/sda |grep -i tem
194 Temperature_Celsius 0x0002 100 100 000 Old_age Always - 29
[root@localhost Desktop]# smartctl -a /dev/sda |grep -i tem |awk '{print $10}'
29
2 系统盘的限高温度为70度,以此为判断
for i in {1..10000};do
os_tem=`smartctl -a /dev/sda |grep -i tem |awk '{print $10}'`
if [ $os_tem -lt 70 ]
then
echo "pass">>result.txt
else
echo "failed">>result.txt
fi
3.跑48h, 2分钟检测一次
#!/bin/bash
rm -rf tempResult.txt
rm -rf temp.txt
for i in {1..1440};do
os_tem=`smartctl -a /dev/sda |grep -i tem |awk '{print $10}'`
if [ $os_tem -lt 70 ]
then
echo "pass">>result.txt
else
echo "failed">>result.txt
fi
echo "============$i==============" |tee -a tempResult.txt
date |tee -a tempResult.txt
echo "m.2 degrees $os_tem" >temp.txt
paste temp.txt result.txt |tee -a tempResult.txt
rm -rf result.txt
rm -rf temp.txt
sleep 120
done
运行结果如下图:
[root@localhost Desktop]# ./temp.sh
============1==============
Mon Jan 10 21:00:10 CST 2022
m.2 degrees 30 pass
============2==============
Mon Jan 10 21:02:10 CST 2022
m.2 degrees 30 pass
============3==============
Mon Jan 10 21:04:10 CST 2022
m.2 degrees 30 pass
============4==============
Mon Jan 10 21:06:10 CST 2022
m.2 degrees 30 pass