Skip to content

Instantly share code, notes, and snippets.

@QNimbus
Last active January 23, 2020 10:52
Show Gist options
  • Save QNimbus/b2ead8cde75bcf9b177b1a9d951d9411 to your computer and use it in GitHub Desktop.
Save QNimbus/b2ead8cde75bcf9b177b1a9d951d9411 to your computer and use it in GitHub Desktop.
Script for use with M/Monit to monitor system temperature
#!/bin/sh -e
##
## Title: SystemTemp.sh
## Description: Script for use with M/Monit to monitor system temperature
## Author: B. van wetten
## Created date: 22-01-2020
## Updated date: 23-01-2020
## Version: 0.2
## GitHub Gist: https://gist.github.com/QNimbus/b2ead8cde75bcf9b177b1a9d951d9411
##
## Usage: SystemTemp.sh [max_temp]
## Sample M/Monit condition: status != 0 for 3 times within 5 cycles
## Notes: Exit code 0 when temperature is greater than 'max_temp'
## otherwise exitcode is equal to system temperature.
## If no command line parameter is supplied 'max_temp' equals 40 degrees
MaxSystemTemp=${1:-40}
CurrentSensor=0
NumSensors=`sysctl hw.acpi.thermal | egrep "hw.acpi.thermal.tz[0-9]" | cut -d "." -f-4 | sort --unique | wc -l`
ExitCode=0
while [ $CurrentSensor -lt $NumSensors ]
do
SystemTemp=`sysctl hw.acpi.thermal.tz${CurrentSensor}.temperature 2> /dev/null | awk '{print $2}' | awk -F. '{print $1}'`
echo "System thermal zone ${CurrentSensor} sensor temperature: ${SystemTemp}"
if [ $? -eq 0 ] && [ $SystemTemp -gt $MaxSystemTemp ] && [ $SystemTemp -gt $ExitCode ]
then
ExitCode=$SystemTemp
fi
CurrentSensor=$((CurrentSensor+1))
done
echo "Maximum system thermal zone temperature allowed: ${MaxSystemTemp}"
exit $ExitCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment