Last active
January 23, 2020 10:54
-
-
Save QNimbus/529ab50d7293a42f7bb2924c27b4b951 to your computer and use it in GitHub Desktop.
Script for use with M/Monit to monitor CPU core temperature
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/sh -e | |
## | |
## Title: CPUTemp.sh | |
## Description: Script for use with M/Monit to monitor CPU core temperature | |
## Author: B. van wetten | |
## Created date: 21-01-2020 | |
## Updated date: 23-01-2020 | |
## Version: 0.3 | |
## GitHub Gist: https://gist.github.com/QNimbus/529ab50d7293a42f7bb2924c27b4b951 | |
## | |
## Usage: CPUTemp.sh [max_temp] | |
## Sample M/Monit condition: status != 0 for 3 times within 5 cycles | |
## Notes: Exit code 0 when no CPU core temperature is greater than 'max_temp' | |
## otherwise exitcode is equal to max core temperature. | |
## If no command line parameter is supplied 'max_temp' equals 60 degrees | |
MaxCPUTemp=${1:-60} | |
NumCPUs=`sysctl -n kern.smp.cpus` | |
CurrentCPU=0 | |
ExitCode=0 | |
while [ $CurrentCPU -lt $NumCPUs ] | |
do | |
CPUTemp=`sysctl dev.cpu.$CurrentCPU.temperature | awk '{print $2}' | awk -F. '{print $1}'` | |
echo "CPU core ${CurrentCPU} temperature: ${CPUTemp}" | |
if [ $CPUTemp -gt $MaxCPUTemp ] && [ $CPUTemp -gt $ExitCode ] | |
then | |
ExitCode=$CPUTemp | |
fi | |
CurrentCPU=$((CurrentCPU+1)) | |
done | |
echo "Maximum CPU core temperature allowed: ${MaxCPUTemp}" | |
exit $ExitCode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment