监测GPU最高温度增加风扇转速

!/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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容