Living in Southern California without A/C I’m always a little worried about the temperature inside my computer cases.  I just rebuilt a system and forgot to plug in the 120mm fan in front of the drives.  When I opened the case up to reconnect the fan the hard drives where scorching hot.  After rebooting I checked the drive temperatures using hddtemp, 59C-66C.  Ouch!  Now with the fan connect, the drives are 42C-48C.

Nothing kills a drive faster then heat, so I decided to start monitoring them.   Here is a script that uses hddtemp to monitor the drive temperature and send out an alert and if the drive reaches critical condition will shut the machine down. To install hddtemp on Ubuntu run: sudo apt-get install hddtemp

#! /bin/bash

#List of devices to monitor
DEVICES="/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf"

#Email address to send alerts to
SYSADMIN=email@address.net

#Mail program
MAIL="/usr/bin/mail"

#Alert temperature before sending alerts
ALERT_TEMP="60"

#Max temperature before shutting down down
KILL_TEMP="65"

SHUTDOWN_CMD="/sbin/shutdown -h now"

for HD in $DEVICES
do
    TEMP=`/usr/sbin/hddtemp -n $HD`
    logger "Checking temperature on $HD... ($TEMP C)";
    if [ "$TEMP" -gt "$ALERT_TEMP" ]; then

        DATA=`/usr/sbin/hddtemp $HD`
        HOSTNAME=`hostname`
        MSG="$HOSTNAME Drive temperature critical"
        #
        (
        echo " "
        echo "$DATA"
        echo " "
        ) | $MAIL -s "$MSG" $SYSADMIN
    fi;

    if [ "$TEMP" -gt "$KILL_TEMP" ]; then
    $SHUTDOWN_CMD
    fi;

done

The following added to cron.d runs the script every 5mins.

*/5 * * * * root /usr/local/bin/hddtemp.sh