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 <#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 ]; 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 <【CPU、GPU温度监控脚本】#$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.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 <#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
fi

转载于:https://blog.51cto.com/shlinuxdream/2147246

    推荐阅读