Überwachung der Onboard-Temperatur

Überwachung der Onboard-Temperatur

Seit einiger Zeit hat mein Pi aufgrund äußerer Umstände eine erhöhte Hitze, trotz Kühlkörpers und luftiger Stelle.
Im Netz habe ich dann ein schönes Script entdeckt was die Temperatur überwacht, benachrichtigt und ggfs. im schlimmsten Fall den Pi herunterfährt.
Für die Benachrichtung benutzen wir swaks, da dieser auch SMTP Zugänge erlaubt, so vermeidet man, das Emails aufgrund Greylisting oder ähnlichem nicht ankommen.

Installation Swaks:
sudo apt-get install swaks

Datei anlegen:
nano /usr/bin/local/tempcheck

Text einfügen:
#!/bin/sh
# This script reads the Broadcom SoC temperature value, alerts the User if it more than 50°C 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="78"
# When Comes Alert
ALERT="55"
# Reciever
RECIEVER="[email protected]"
# Sender
SENDER="[email protected]"
# Password
PASSWORD="yourpassword"
# Mailserver
MAILSERVER="mail.domain.tld"
# Name
NAME="Mein Raspberry Pi"

if [ "${TEMP}" -gt "${ALERT}" ]
then
# Email for Alert
echo "${NAME} - ALERT - SoC temp is on ${TEMP} \°C." | mailx \
-r "${SENDER} <${NAME}>" \
-s "ALERT - ${NAME} - SoC temp is on ${TEMP} °C." \
-a "Importance: high" \
smtp="${MAILSERVER}" \
smtp-use-starttls \
smtp-auth=login \
smtp-auth-user="$REVIEVER" \
smtp-auth-password="$PASSWORD" \
ssl-verify=ignore \
"$RECIEVER"

# Send Mail Without Authentification ( missing A or MX DNS record leads to Error's)
# echo "ALERT - SoC temp is on ${TEMP}." | mail -s "ALERT - SoC temp is on ${TEMP}." "${RECIEVER}"
elif [ "${TEMP}" -gt "${MAX}" ]
then
# Email for Alert
echo "ALERT - ${NAME} - Shutting down due to SoC temp ${TEMP} \°C." | mailx \
-r "${SENDER}" \
-s "ALERT - ${NAME} - Shutting down due to SoC temp ${TEMP} °C." \
-a "Importance: high" \
smtp="${MAILSERVER}" \
smtp-use-starttls \
smtp-auth=login \
smtp-auth-user="$REVIEVER" \
smtp-auth-password="$PASSWORD" \
ssl-verify=ignore \
"$RECIEVER"

# 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
/sbin/shutdown -h now
else
exit 0
fi

Datei ausführ machen:
chmod u+x /usr/bin/local/tmpcheck

Cronjob anlegen:
crontab -e

Cronjob:
*/5 * * * * /usr/bin/local/tempcheck

Schon meldet sich der Raspberry Pi, sofern es zu heiß wird und schaltet sich ggfs. ab.