Skip to content

Instantly share code, notes, and snippets.

@JMac87 JMac87/cpu_temp_alert.sh Secret
Last active Feb 21, 2018

Embed
What would you like to do?
pfSense - Temperature Alert Script
#!/bin/sh
#==================================================================
#title :cpu_temp_alert.sh
#description :This script will find the average temperature of
# the CPU and fire off an email if this temperature
# is over a set limit ($alert).
#author :Justin Maciak
#date :20160725
#version :1.0
#usage :./cpu_temp_alert.sh
#==================================================================
#Change the following number to the temperature you'd like to be alerted at
alert=55
#Get number of CPU cores
ncpu=$( sysctl hw.ncpu | awk '{ print $2 }' )
#Set hostname
thishost=$(hostname)
#Get temperature
get_temp() {
avg=0
for c in `jot ${ncpu} 0`; do
temp=$( sysctl dev.cpu.${c}.temperature | sed -e 's|.*: \([0-9.]*\)C|\1|' )
avg=$( echo "${avg} + ${temp}" | bc )
done
avg=$( echo "${avg} / (${ncpu})" | bc )
}
get_temp
#Compare current average temperature to alert threshold, email if equal or over
if [ "$avg" -gt "$alert" ]; then
echo "WARNING: ${thishost} is currently at ${avg}C, which is over the alert threshold of ${alert}C" | /usr/local/bin/php -q /usr/local/bin/mail.php -s"ALERT: ${thishost} Temperature At ${avg}C"
exit 1;
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.