当前位置:网站首页>树莓派温度监视关机保护脚本
树莓派温度监视关机保护脚本
2022-08-04 17:18:00 【ttyt1217】
树莓派温度监控保护脚本,超过70度过热时提醒,超过80度过热3次后时提醒并关机自保,记录异常温度到log。
Shell脚本(/home/pi/myboot/temperatureMonitor.sh):
#!/bin/sh
# OVER HOT Temp
hot_temp=80.0
# OVER HOT Count
hot_cnt=0
while (true) do
cur_time=$(date "+%Y-%m-%d %H:%M:%S")
temp=`/opt/vc/bin/vcgencmd measure_temp|awk -F= '{print $2}'|awk -F\' '{print $1}'`
if [ `expr "$temp > $hot_temp"` ]; then
if [ $hot_cnt > 3 ]; then
echo $cur_time' Temp = '$temp' degree'
echo "ERROR: OVER HOT! System needs to shutdown!"
echo "ERROR: OVER HOT! System needs to shutdown!" >&2
sleep 3
halt -p
break
else
let hot_cnt+=1
fi
else
#if over hot 3 times then shutdown
hot_cnt=0
cold_cnt=0
if [ `expr "$temp < 0.0"` ]; then # Cold
echo $cur_time' Temp = '$temp' degree'
echo "Warning: Cold! Temperature LOW!"
echo "Warning: Cold! Temperature LOW!" >&2
elif [ `expr "$temp < 40.0"` ]; then # Standby
sleep 0.1
#echo $cur_time' Temp = '$temp' degree'
#echo "Info: Standby!"
#echo "Info: Standby!" >&2
elif [ `expr "$temp < 70.0"` ]; then # Working
sleep 0.1
#echo $cur_time' Temp = '$temp' degree'
#echo "Info: Working!"
#echo "Info: Working!" >&2
elif [ `expr "$temp < $hot_temp"` ]; then # OVER HOT
echo $cur_time' Temp = '$temp' degree'
echo "Warning: HOT! Temperature OVER 70, Pls make it down!"
echo "Warning: HOT! Temperature OVER 70, Pls make it down!" >&2
fi
fi
sleep 10
done
chmod 755 /home/pi/myboot/temperatureMonitor.sh
开机启动的服务配置文件(/etc/systemd/system/tempMonitor.service):
[Unit]
Description=Temperature Monitor
After=network.target
[Service]
ExecStart=/home/pi/myboot/temperatureMonitor.sh >> /var/log/myboot/temperatureMonitor.log &
Restart=on-abort
[Install]
WantedBy=multi-user.target
chmod 755 /var/log/myboot/temperatureMonitor.log
执行 systemctl enable tempMonitor 使 开机启动温控脚本有效化。
【参考资料】[RPI]树莓派监控温度及报警关机保护:https://blog.csdn.net/tzwsoho/article/details/100653014
边栏推荐
猜你喜欢

多线程学习笔记-3.并发容器

并发编程原理学习-reentrantlock源码分析

要有遥不可及的梦想,也要有脚踏实地的本事

Boost库学习笔记(一)安装与配置
The second step through MySQL in four steps: MySQL index learning

IDEA以多端口启动同一个服务项目

88. (the home of cesium) cesium polymerization figure

基于clipboard.js对复制组件的封装

mysqlbinlog 超过500g自动删除,保留7个,求大深给个版本

Understand Chisel language. 32. Chisel advanced hardware generator (1) - parameterization in Chisel
随机推荐
【商家联盟】云平台—异业联盟,打造线上线下商业相结合的系统
谷歌开发者社区推荐:《Jetpack Compose 从入门到实战》新书上架,带你踏上 Compose 开发之旅~
如何模拟后台API调用场景,很细!
机器学习(十三):支持向量机(SVM)
拼多多详情API接口深度解读
win11如何退出安全模式
两个对象相同数据赋值
图扑软件与华为云共同构建新型智慧工厂
JVM内存和垃圾回收-08.方法区
localhost,127.0.0.1,本机IP
从云计算到函数计算
要有遥不可及的梦想,也要有脚踏实地的本事
华硕win11安全启动如何开启
.NET云原生应用发展论坛--8月7日邀你一起云上探索
mysqlbinlog 超过500g自动删除,保留7个,求大深给个版本
SRM Supplier Collaborative Management System Function Introduction
hi, 请问下这是什么问题, 我看官网的example就是mysql的, 咋提示不支持?
WEB 渗透之越权
WEB 渗透之SSTI 模板注入
pyhon爬虫之爬取图片(亲测可用)