Monitor Hard Disk Temperature in Ubuntu/Debian1 min read

**Required Software**

 apt-get install smartmontools

Then, we’ll create a simple script.

 nano /root/scripts/temperature_monitor.sh

Paste this in…

 #! /bin/bash
DISKS="`blkid | grep sd | cut -c 1-8 | uniq`"
SMART=/usr/sbin/smartctl
ARGS="-a -d ata"
LOG=/usr/bin/logger
DOWN=/sbin/shutdown
ALERT_LEVEL=55
for disk in $DISKS
do
 if [ -b $disk ]; then
 HDTEMP=$($SMART $ARGS $disk | grep -m 1 Temperature | awk '{print $10}')
 if [ $HDTEMP -ge $ALERT_LEVEL ]; then
 $LOG "System going down as hard disk : $disk temperature $HDTEMP°C crossed its limit"
 sync;sync
 $DOWN -h 0
 fi
 fi
done

*Press ctrl+x, then y to save and quit nano* This script will find all hard drives connected via SATA, and if SMART monitoring is enabled on them, will check the temperature and shut the system down if it’s above the temperature threshold of 55°C. *Note: This script will not work as is with IDE disks, or disks in a hardware RAID array* Next, we need to make the script executable.

 chmod +x /root/scripts/temperature_monitor.sh

And add it to your root cronjob

 crontab -e

Your cron entry should look like this.

 */15 * * * * /root/scripts/temperature_monitor.sh

The above will set the script to run every 15 minutes.

Zack

I love learning new things and trying out the latest technology.

You may also like...

2 Responses

  1. kiwijunglist says:

    Doesn’t this script wake all the HDDs up every 15 minutes?

    Don’t you need to use -n standby or -n idle

    • Zack says:

      Yes, this script will wake up disks every 15 minutes without the standby option. As an FYI, I don’t bother with monitoring my hard drive temps with this script.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.