当前位置:网站首页>树莓派温度监视关机保护脚本
树莓派温度监视关机保护脚本
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每日一题】——374.猜数字大小

shell脚本详解-------循环语句wuile循环和until循环

15 days to upgrade to fight monsters and become a virtual fashion creator

Learning to Explore - Setting the Foreground Color for Fonts

codeforces每日5题(均1600)-第二十八天

How to convert an int attribute into a string in the json format returned by the Go language gin framework?

力拓信创生态,博睿数据多款产品获得东方通与达梦数据库产品兼容互认证明

不需要服务器,教你仅用30行代码搞定实时健康码识别

动态数组底层是如何实现的

【LeetCode每日一题】——540.有序数组中的单一元素
随机推荐
【 Gazebo introductory tutorial] speak the second model library into robot modeling and visualization (editor) model
C. LIS or Reverse LIS?
安装win11提示开启安全模式如何解决
How to convert an int attribute into a string in the json format returned by the Go language gin framework?
身为程序员的我们如何卷死别人?破局重生。
多线程学习笔记-3.并发容器
机器学习(十三):支持向量机(SVM)
华为云数据治理生产线DataArts,让“数据‘慧’说话”
hi, 请问下这是什么问题, 我看官网的example就是mysql的, 咋提示不支持?
《机器学习理论到应用》电子书免费下载
WPF 修改 ItemContainerStyle 鼠标移动到未选中项效果和选中项背景
域名哪家便宜?怎么买便宜域名?
西西成语接龙小助手
数字化金融企业的产品体系长啥样?
R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化柱状图、color参数指定柱状图的边框的色彩
动态数组底层是如何实现的
What does the product system of a digital financial enterprise look like?
R语言缺失时间序列的填充及合并:补齐时间序列数据中所有缺失的时间索引、使用merge函数合并日期补齐之后的时间序列数据和另外一个时间序列数据(补齐左侧数据)
SRM供应商协同管理系统功能介绍
Understand Chisel language. 32. Chisel advanced hardware generator (1) - parameterization in Chisel