Skip to content

Instantly share code, notes, and snippets.

@palaniraja
Last active September 9, 2023 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palaniraja/b949cd58de9a8a2a823e087c1e1445e5 to your computer and use it in GitHub Desktop.
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
#!/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
# run everyminute, paranoid after I smoked pi2 intially with the same photo frame experiment
*/1 * * * * ~/autoshutdown.sh
@ve3
Copy link

ve3 commented Apr 15, 2023

Here is updated.

#!/bin/sh
#
#  @link https://forums.raspberrypi.com/viewtopic.php?t=56911 Original source code.
#  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="`/usr/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
 sudo /sbin/shutdown -h now
else
  # echo "Temperature is ${TEMP}." # for testing only.
  exit 0
fi

Changes:

Additional usage:

For anyone who is not familiar with Linux, Debian (like I am).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment