CPU、GPU温度监控脚本
#!/bin/bash
passwd=emdata2018
today=date +%Y%m%d
mulu=/home/user/cpuwd/log
touch $mulu/CPU$today.log
touch $mulu/CPUGW$today.log
touch $mulu/GPU$today.log
touch $mulu/GPUGW$today.log
touch $mulu/GJ_log
sensors |awk '{print $4}' |egrep '^+' |sed 's/+//' |while read temp
do
if [[ $temp > 70 ]];
then
echo "$(date +%Y-%m-%d-%T) CPU $temp is High Temperature $( expr `date +%H` \* 60 + `date +%M` )" >>$mulu/CPUGW_$today.logelse
echo "$(date +%Y-%m-%d-%T) CPU $temp is Temperature OK $( expr `date +%H` \* 60 + `date +%M` )" >>$mulu/CPU_$today.log
fi if [[ $temp > 80 ]];
then
echo "$(date +%Y-%m-%d-%T) CPU temperature exceeds 80C,After 3 seconds is about to shut down" >>$mulu/GJ_log
sudo -S shutdown -h now <
fi
done
a=
grep "$(date -d '-10min' "+%Y-%m-%d-%H:%M")" $mulu/CPUGW_$today.log
b=
grep "$(date "+%Y-%m-%d-%H:%M")" $mulu/CPUGW_$today.log
A=
grep "$(date -d '-10min' "+%Y-%m-%d-%H:%M")" $mulu/CPUGW_$today.log |awk '{print $7}'|head -1
B=
grep "$(date "+%Y-%m-%d-%H:%M")" $mulu/CPUGW_$today.log |awk '{print $7}'|head -1
C=
expr "$B" - "$A"
if [ $C > 9 ];
thenecho $a >>$mulu/GJ_log
echo $b >>$mulu/GJ_log
echo $C Min CPU guanji
echo "$(date +%Y-%m-%d-%T) CPU lasts 10 minutes high temperature,After 3 seconds is about to shut down" >>$mulu/GJ_log
sudo -S shutdown -h now <
#EOF
fi
nvidia-smi -q -i 0,1,2,3,4,5,6,7 -d TEMPERATURE | grep "GPU Current" |awk '{print $5}' |while read tmp
do
if [[ $tmp > 90 ]]; then
echo "$(date +%Y-%m-%d-%T) GPU $tmp is High Temperature $( expr `date +%H` \* 60 + `date +%M` )" >>$mulu/GPUGW_$today.logelse
echo "$(date +%Y-%m-%d-%T) GPU $tmp is Temperature OK $( expr `date +%H` \* 60 + `date +%M` )" >>$mulu/GPU_$today.log
fi if [[ $tmp > 99 ]];
thenecho "$(date +%Y-%m-%d-%T) GPU temperature exceeds 80C,After 3 seconds is about to shut down" >>$mulu/GJ_log
sudo -S shutdown -h now <
fi
done
x=
grep "$(date -d '-10min' "+%Y-%m-%d-%H:%M")" $mulu/GPUGW_$today.log
y=
grep "$(date "+%Y-%m-%d-%H:%M")" $mulu/GPUGW_$today.log
X=
grep "$(date -d '-10min' "+%Y-%m-%d-%H:%M")" $mulu/GPUGW_$today.log |awk '{print $7}'|head -1
Y=
grep "$(date "+%Y-%m-%d-%H:%M")" $mulu/GPUGW_$today.log |awk '{print $7}'|head -1
Z=
expr "$Y" - "$X"
if [ $Z > 9 ]; then
echo $x >>$mulu/GJ_log
echo $y >>$mulu/GJ_log
echo $Z Min GPU guanji
echo "$(date +%Y-%m-%d-%T) GPU lasts 10 minutes high temperature,After 3 seconds is about to shut down" >>$mulu/GJ_log
sudo -S shutdown -h now <
fi
转载于:https://blog.51cto.com/shlinuxdream/2147246
推荐阅读
- 一个人的碎碎念
- 野营记-第五章|野营记-第五章 讨伐梦魇兽
- Shell-Bash变量与运算符
- 清明,是追思、是传承、是感恩。
- 牛人进化+|牛人进化+ 按自己的意愿过一生
- 七老修复好敏感、角质层薄、红血丝
- 华为旁!大社区、地铁新盘,佳兆业城市广场五期!
- 标签、语法规范、内联框架、超链接、CSS的编写位置、CSS语法、开发工具、块和内联、常用选择器、后代元素选择器、伪类、伪元素。
- 螃蟹和这些食物同吃,轻则腹泻、重则中毒!要小心哦~
- 八、「料理风云」