Last active
September 9, 2023 19:45
-
-
Save palaniraja/b949cd58de9a8a2a823e087c1e1445e5 to your computer and use it in GitHub Desktop.
auto-shutdown on higher temprature for raspberrypi - kill kodi & fbi along - copied from raspberrypi forum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script reads the Broadcom SoC temperature value and shuts down if it | |
# exceeds a particular value. | |
# 80ºC is the maximum allowed for a Raspberry Pi. | |
# Get the reading from the sensor and strip the non-number parts | |
SENSOR="`/opt/vc/bin/vcgencmd measure_temp | cut -d "=" -f2 | cut -d "'" -f1`" | |
# -gt only deals with whole numbers, so round it. | |
TEMP="`/usr/bin/printf "%.0f\n" ${SENSOR}`" | |
# How hot will we allow the SoC to get? | |
MAX="60" | |
if [ "${TEMP}" -gt "${MAX}" ] ; then | |
# This will be mailed to root if called from cron | |
echo "${TEMP}ºC is too hot!" | |
# Send a message to syslog | |
/usr/bin/logger "Shutting down due to SoC temp ${TEMP}." | |
# Halt the box | |
pkill fbi | |
pkill kodi | |
sudo /sbin/shutdown -h now | |
echo "Initiating shutdown..." | |
else | |
exit 0 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run everyminute, paranoid after I smoked pi2 intially with the same photo frame experiment | |
*/1 * * * * ~/autoshutdown.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is updated.
Changes:
/opt/vc/bin/vcgencmd
is not found. ( https://forums.raspberrypi.com/viewtopic.php?t=164985#p1064312 as reference. )Additional usage:
For anyone who is not familiar with Linux, Debian (like I am).
sudo chmod +x auto-shutdown.sh
on the location where this file is. ( https://www.linuxjournal.com/content/how-create-shell-script-linux as reference. )sudo auto-shutdown.sh
.sudo tail /var/log/syslog
. ( https://www.linuxfoundation.org/blog/blog/classic-sysadmin-viewing-linux-logs-from-the-command-line as reference. )sudo crontab -e
and follow instruction. Usesudo crontab
because this file needsudo
(root level) to run.sudo crontab -l
.