Depending on your server's room conditions it may be important to be informed about server's hard drive temperature. System administrator may use bash and cron to write a simple script to alert about sudden temperature change. Such a script can be based on inxi or hddtemp command line tools. Using inxi tool now we can determine hard-drives temperature for a block device /dev/sda:
# inxi -xD 
Drives:    HDD Total Size: 75.5GB (70.3% used) ID-1: /dev/sda model: HTS721060G9SA00 size: 60.0GB temp: 35C
           ID-2: USB /dev/sdb model: TransMemory size: 15.5GB temp: 0C
The hardrive temperature of /dev/sda is 35C. Note that the above command needs to be run with root administrative privileges. The same can be achieved with hddtemp command, but first we need to determine block device file name belonging to the hard drive in question. This can be achieved by:
]$ lsscsi -g
[2:0:0:0]    disk    ATA      HTS721060G9SA00  MC3I  /dev/sda   /dev/sg0

Next run hddtemp command command against the actual hard drive's block device name:
# hddtemp /dev/sda
/dev/sda: HTS721060G9SA00: 36°C
If your intention is to wire a monitoring script to regularly check hard drive's temperature use the below script as your starting point:

temperature=$(hddtemp /dev/sda | cut -d : -f3 | sed 's/[^0-9]*//g')

# REPORT when hard drive's temperature is above 50C

if [ $temperature -ge 50 ]; then
	echo "ALERT: hard drive's temperature is above: $temperature"

Free Linux eBooks

Go to top