Last active
May 26, 2017 18:42
-
-
Save il-katta/1f432c0b3518e3ca7da21f9420c024d7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bash | |
# author: Andrea Cattaneo | |
# check raspberry pi cpu temperature with perfdata and warn/crit thresholds | |
# | |
# check raspberry pi temperature with perfdata and warn/crit thresholds. | |
# The data is read from sysfs ( file: /sys/class/thermal/thermal_zone0/temp ). | |
# | |
# Dependency: awk bc | |
# licence: GPL | |
if [ -z "$1" ] ; then | |
echo "UNKNOWN - missing warning temperature" | |
exit 3 | |
fi | |
WARN=$1 | |
if [ -z "$2" ] ; then | |
echo "UNKNOWN - missing critical temperature" | |
exit 3 | |
fi | |
CRIT=$2 | |
if ! ( command -v awk >/dev/null ) ; then | |
echo "UNKNOWN - awk command not found" | |
exit 3 | |
fi | |
if ! ( command -v bc >/dev/null ) ; then | |
echo "UNKNOWN - bc command not found" | |
exit 3 | |
fi | |
if ! [[ -f /sys/class/thermal/thermal_zone0/temp ]] ; then | |
echo "UNKNOWN - /sys/class/thermal/thermal_zone0/temp: No such file" | |
exit 3 | |
fi | |
TEMP=`awk '{printf "%3.1f", $1/1000}' /sys/class/thermal/thermal_zone0/temp` | |
if (( $(echo "${TEMP} > ${CRIT}" | bc -l) )); then | |
echo "TEMPERATURE CRITICAL - CPU Temp: ${TEMP} °C | cpu_temp=${TEMP};${WARN};${CRIT};;" | |
exit 2 | |
fi | |
if (( $(echo "${TEMP} > ${WARN}" | bc -l) )); then | |
echo "TEMPERATURE WARNING - CPU Temp: ${TEMP} °C | cpu_temp=${TEMP};${WARN};${CRIT};;" | |
exit 1 | |
fi | |
echo "TEMPERATURE OK - CPU Temp: ${TEMP} °C | cpu_temp=${TEMP};${WARN};${CRIT};;" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment