码迷,mamicode.com
首页 > 其他好文 > 详细

CPU、GPU温度监控脚本

时间:2018-07-19 16:09:46      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:temp   out   bin   after   oda   ash   gpu   seconds   tmp   

#!/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.log  

    else
     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 <<EOF

#$passwd
#EOF
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 ];then

     echo $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

#$passwd
#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.log

      else
          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 ]];then  

      echo "$(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 <<EOF

#$passwd
#EOF
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 <<EOF

#$passwd
#EOF

 fi

CPU、GPU温度监控脚本

标签:temp   out   bin   after   oda   ash   gpu   seconds   tmp   

原文地址:http://blog.51cto.com/shlinuxdream/2147246

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!