当前位置:网站首页>树莓派温度监视关机保护脚本
树莓派温度监视关机保护脚本
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
边栏推荐
- 软件测试高频面试题真实分享/网上银行转账是怎么测的,设计一下测试用例。
- 数字化金融企业的产品体系长啥样?
- 全球电子产品需求萎靡:三星越南工厂大幅压缩产能,减少工人工作日
- The second step through MySQL in four steps: MySQL index learning
- 知乎高赞:拼多多和国家电网,选哪个?
- icu是哪个国家的域名?icu是什么域名?
- 机器学习入门到大神专栏总览
- .NET云原生应用发展论坛--8月7日邀你一起云上探索
- 15 days to upgrade to fight monsters and become a virtual fashion creator
- Selenium Webdriver驱动自管理
猜你喜欢
随机推荐
(1), the sequential storage structure of linear table chain storage structure
水能自发变成“消毒水”,83岁斯坦福教授:揭示冬天容易得流感的部分原因...
罗振宇折戟创业板/ B站回应HR称用户是Loser/ 腾讯罗技年内合推云游戏掌机...今日更多新鲜事在此...
R语言使用cov函数计算矩阵或者dataframe数据变量之间的协方差、cor函数计算相关性、cor函数通过method参数指定相关性、相关性计算方法Pearson,Spearman, Kendall
机器学习(十):朴素贝叶斯
安装失败怎么办
知乎高赞:拼多多和国家电网,选哪个?
SRM供应商协同管理系统功能介绍
软件基础的理论
Qt自动补全之QCompleter使用
字节二面被问到mysql事务与锁问题,我蚌埠住了
R语言使用yardstick包的gain_curve函数评估多分类(Multiclass)模型的性能、查看模型在多分类每个分类上的增益(gain)曲线(gain curve)
机器学习(十七):网格搜索(Grid Search)和SVM
乐享购(分享购)的模式:优势、亮点、收益
正则过滤字符串中 script 标签
拼多多详情API接口深度解读
R语言dplyr包group_by函数和summarise_at函数计算dataframe计算不同分组的计数个数和均值、使用%>%符号将多个函数串起来
JSP 标准标签库(JSTL)[通俗易懂]
Flutter实战-请求封装(四)之gzip报文压缩
西西成语接龙小助手








