当前位置:网站首页>树莓派温度监视关机保护脚本
树莓派温度监视关机保护脚本
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
- Understand Chisel language. 32. Chisel advanced hardware generator (1) - parameterization in Chisel
- 海报 | 夏季高温,危化品安全风险的注意事项必须get!
- R语言dplyr包group_by函数和summarise_at函数计算dataframe计算不同分组的计数个数和均值、使用%>%符号将多个函数串起来
- 小程序+自定义插件的混合模式
- 机器学习(十九):梯度提升回归(GBR)
- R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化柱状图、color参数指定柱状图的边框的色彩
- jMeter Transaction Controller 学习笔记
- WPF 修改 ItemContainerStyle 鼠标移动到未选中项效果和选中项背景
- 集群监控——Zabbix使用
猜你喜欢
88. (the home of cesium) cesium polymerization figure
ctfshow 萌新web1-21
租房小程序登顶码云热门
并发编程原理学习-reentrantlock源码分析
【LeetCode Daily Question】——374. Guess the size of the number
15 days to upgrade to fight monsters and become a virtual fashion creator
Boost library study notes (1) Installation and configuration
NLP未来,路在何方?从学术前沿和业界热点谈起
移动平台助力推进智慧型科研院所信息化建设
吃透Chisel语言.32.Chisel进阶之硬件生成器(一)——Chisel中的参数化
随机推荐
小程序+自定义插件的混合模式
SAP ABAP SteammPunk 蒸汽朋克的最新进展 - 嵌入式蒸汽朋克
WEB 渗透之XXE&XML
icu是哪个国家的域名?icu是什么域名?
机器学习(十):朴素贝叶斯
安装win11提示开启安全模式如何解决
安装失败怎么办
力拓信创生态,博睿数据多款产品获得东方通与达梦数据库产品兼容互认证明
R语言使用ggpubr包的ggsummarystats函数可视化柱状图(通过ggfunc参数设置)、在可视化图像的下方添加描述性统计结果表格、palette参数配置柱状图及统计数据的颜色
response的contentType 几种类型
Digital-intelligent supply chain management system for chemical manufacturing industry: build a smart supply system and empower enterprises to improve production efficiency
yarn详细入门教程
谷歌开发者社区推荐:《Jetpack Compose 从入门到实战》新书上架,带你踏上 Compose 开发之旅~
IDEA以多端口启动同一个服务项目
The second step through MySQL in four steps: MySQL index learning
【图像分类】2021-DeiT
R语言ggpubr包的ggtexttable函数可视化表格数据(直接绘制表格图或者在图像中添加表格数据)、使用ggarrange函数将表格数据和可视化图像组合起来(表格数据在可视化图像下方)
codeforces每日5题(均1600)-第二十八天
学习探索-网站中引入百度统计
【商家联盟】云平台—异业联盟,打造线上线下商业相结合的系统