Poor man's cpu temp watcher
Wednesday, June 30, 2010 at 10:58PM
Captain Rtfb

It's getting hot in our small country! Temperatures above 37 degrees Celcius (99 deg. F) are expected tomorrow. Will the servers in our compound stand the heat? No need for alarming applications which only produce more heat, just a few bash lines using the unix 'sensors' command will do!

 

First make sure your sensors are set up right. Run the command 'sensors-detect' to automatically generate a suitable config file for your cpu board. Answer default on all questions. Then try to run the 'sensors' command and find out if your cpu temperature is reported.

 

The script:

#!/bin/bash

TEMP1=`sensors | grep  'temp2' | cut -c15-16`
sleep 1
TEMP2=`sensors | grep  'temp2' | cut -c15-16`
sleep 1
TEMP3=`sensors | grep  'temp2' | cut -c15-16`

AVG_TEMP=$((($TEMP1+$TEMP2+$TEMP3)/3))

echo $TEMP1
echo $TEMP2
echo $TEMP3
echo $AVG_TEMP

if [ "$AVG_TEMP" -gt 45 ]; then
    echo "Average of three $TEMP1 $TEMP2 $TEMP3" | mail -s "Temperature alert! Average $AVG_TEMP celcius" captainftfb@dutchtechies.com
fi

 

And place the script in a cronjob, running every half hour.

 

Article originally appeared on dutchtechies (http://dutchtechies.com/).
See website for complete article licensing information.