You state you wish to check the servers temperature but using
hddtemp would be
"fine". Sounds like you'd rather get your data from somewhere else.
I suggest using
lm-sensors which will most likely by available to you via your
own distribution repository. For example, to install it under Debian/Ubuntu:
sudo
apt-get install lm-sensorsThe use of
lm-sensors will allow your bash script to be portable amongst
different distributions and releases. It gives you the flexibility to pick and choose what
sensors you wish to monitor.
Once installed, open/shh into terminal and execute the command
sensors. This
will list all the sensors installed on your system, each with a name and a reading, choose
which one you wish to monitor and replace SENSORNAME with the sensor name in the bash script
below:
#!/bin/bash
# Email an alert should be sent to in the event the reading exceeds the trigger
email=your@email.com
# Trigger amount in Celsuis
temp_trigger=50
# Extract the reading of our desired sensor using the 'sensors' command
temp=$(sensors|grep 'SENSORNAME' | awk '{print $2}' | cut -b2,3,4,5)
# Round our temperature reading to the nearest whole number
rounded_temp=$(echo $temp | awk '{printf("%d\n",$1 + 0.5)}')
# Compare the temperature reading with our alert trigger
if [ $rounded_temp -ge $temp_trigger ]; then
# Send an email alerting the admin!
echo "Temperature is $temp Celsius" | mailx -s "SERVER TEMP TRIGGER" $email
else
# All is okay :)
echo "Temperature is $temp Celsius"
fi
You can have as many of these scripts as you want to monitor any sensor you wish. If the
readings from
sensors don't come out in the format of:
+65.0°C .
The above code may need to tweaked. If so, you can just email me and I will change it for
you: smasterross [at] gmail [dot] com