当前位置:网站首页>树莓派温度监视关机保护脚本
树莓派温度监视关机保护脚本
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
边栏推荐
- 图扑软件与华为云共同构建新型智慧工厂
- 太一集团宣布全资收购火币旗下社交产品火信
- 谷粒商城笔记
- 【LeetCode Daily Question】——374. Guess the size of the number
- SRM供应商协同管理系统功能介绍
- php如何查询字符串以什么开头
- 机器学习(十四):K均值聚类(kmeans)
- 御神楽的学习记录之基于FPGA的AHT10温湿度数据采集
- 移动平台助力推进智慧型科研院所信息化建设
- R语言ggpubr包的ggline函数可视化折线图、设置add参数为mean_se和dotplot可视化不同水平均值的折线图并为折线图添加误差线(se标准误差)和点阵图、设置折线和数据点边框颜色
猜你喜欢
随机推荐
使用Redis做某个时间段在线数统计
yarn详细入门教程
88.(cesium之家)cesium聚合图
华硕win11安全启动如何开启
SAP ABAP SteammPunk 蒸汽朋克的最新进展 - 嵌入式蒸汽朋克
Nacos集群搭建
R语言使用ggpubr包的ggsummarystats函数可视化柱状图(通过ggfunc参数设置)、在可视化图像的下方添加描述性统计结果表格、palette参数配置柱状图及统计数据的颜色
不需要服务器,教你仅用30行代码搞定实时健康码识别
我的大一.
开发一套高容错分布式系统
Cron表达式
R语言使用yardstick包的gain_curve函数评估多分类(Multiclass)模型的性能、查看模型在多分类每个分类上的增益(gain)曲线(gain curve)
codeforces每日5题(均1600)-第二十八天
提高图片清晰度的快速方法?
御神楽的学习记录之基于FPGA的AHT10温湿度数据采集
JSP 标准标签库(JSTL)[通俗易懂]
The use of QCompleter for Qt auto-completion
JSP的Web监听器(Listener)
mysqlbinlog 超过500g自动删除,保留7个,求大深给个版本
全球电子产品需求萎靡:三星越南工厂大幅压缩产能,减少工人工作日









