!/bin/bash
while true; do
temperature=$(nvitop --once | grep 350W | awk '{for(i=1;i<=NF;i++){if($i~/[0-9]+C/){print $i}}}' | tr 'C ' '\n' | sort -n | tail -n 1)
if [[ "$temperature" -gt 50 ]]; then
time_str=$(date "+%Y-%m-%d %H:%M:%S")
echo "${time_str} Temperature $temperature exceeds 50C, loading CPU..." >> /home/ai/cpu_temp.log
# 使用 stress 工具使 CPU 满载30秒。
stress --cpu 24 --timeout 30s
time_str=$(date "+%Y-%m-%d %H:%M:%S")
echo "${time_str} CPU load complete." >> /home/ai/cpu_temp.log
else
time_str=$(date "+%Y-%m-%d %H:%M:%S")
echo "${time_str} Temperature $temperature is normal." >> /home/ai/cpu_temp.log
fi
# 可选:添加一个延迟,以避免过于频繁的检查。
sleep 2 # 每2秒检查一次。
done