当前位置:网站首页>树莓派温度监视关机保护脚本
树莓派温度监视关机保护脚本
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
边栏推荐
- 学习探索-给字体设置前景色
- 化学制品制造业数智化供应链管理系统:打造智慧供应体系,赋能企业产效提升
- 容器化 | 在 NFS 备份恢复 RadonDB MySQL 集群数据
- ctfshow 萌新web1-21
- 基于clipboard.js对复制组件的封装
- 力拓信创生态,博睿数据多款产品获得东方通与达梦数据库产品兼容互认证明
- 抖音最重要的接口——item_search_video-根据关键词获取视频列表
- response的contentType 几种类型
- 罗振宇折戟创业板/ B站回应HR称用户是Loser/ 腾讯罗技年内合推云游戏掌机...今日更多新鲜事在此...
- yarn detailed introductory tutorial
猜你喜欢

海报 | 夏季高温,危化品安全风险的注意事项必须get!

谷歌开发者社区推荐:《Jetpack Compose 从入门到实战》新书上架,带你踏上 Compose 开发之旅~

Catering Supply Chain Management System

学习探索-网站中引入百度统计

Boost library study notes (1) Installation and configuration

吃透Chisel语言.32.Chisel进阶之硬件生成器(一)——Chisel中的参数化

localhost,127.0.0.1,本机IP

小满nestjs(第一章 介绍nestjs)

44. 通配符匹配 ●●● & HJ71 字符串通配符 ●●

Fork/Join框架
随机推荐
Digital-intelligent supply chain management system for chemical manufacturing industry: build a smart supply system and empower enterprises to improve production efficiency
R语言时间序列数据算术运算:使用diff函数计算时间序列数据的逐次差分、使用时间序列之间的除法计算相对变化率(乘以100获得百分比)
乐享购(分享购)的模式:优势、亮点、收益
icu是哪个国家的域名?icu是什么域名?
What does the product system of a digital financial enterprise look like?
小程序+自定义插件的混合模式
yarn详细入门教程
机器学习(十六):主成成分分析(PCA)
el-date-picker 设置时间范围
win11如何退出安全模式
字节二面被问到mysql事务与锁问题,我蚌埠住了
动态数组底层是如何实现的
身为程序员的我们如何卷死别人?破局重生。
【图像分类】2021-DeiT
数字化金融企业的产品体系长啥样?
(1), the sequential storage structure of linear table chain storage structure
图扑软件与华为云共同构建新型智慧工厂
R语言ggplot2可视化:使用patchwork包的plot_layout函数将多个可视化图像组合起来,nrow参数指定行的个数、byrow参数指定按照列顺序排布图
学习探索-网站中引入百度统计
C# Sqlite database construction and use skills