Skip to content

Instantly share code, notes, and snippets.

@JMac87
Last active March 30, 2021 13:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JMac87/1303f78c56a54165447568318eeca3b3 to your computer and use it in GitHub Desktop.
Save JMac87/1303f78c56a54165447568318eeca3b3 to your computer and use it in GitHub Desktop.
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