Gentoo Wiki


This HOWTO is about installing a service to check the temperature of your harddisk once in a while. And send an email (or do other action) if the temperature gets too high.

I need this construct to get notified, if the disks of my server get too warm. Harddisks in over temperature may fail earlier, so I needed some notificator to take action.

The installation of this stuff is quite forward. All we need is

You don't need to install mailto, if you don't like it. This is just one option to take action, if your disks get too warm.


Install hddtemp

First get hddtemp by

$ emerge hddtemp

After that do test if hddtemp is working properly

$ hddtemp /dev/hd{a,b,c}

If you get something like

WARNING: Drive /dev/hda doesn't appear in the database of supported drives
WARNING: But using a common value, it reports something.
WARNING: Note that the temperature shown could be wrong.
WARNING: See --help, --debug and --drivebase options.
WARNING: And don't forget you can add your drive to hddtemp.db

then your database file may be too old (or the drive too new :-) You can update your drive manually by editing the database file. Which is currently in /usr/share/hddtemp/hddtemp.db Get the model description of your drive by

$ hddtemp -D /dev/hda | grep Model
Model: HDS722525VLAT80

Take that model descriptor and add it to the database

"HDS722525VLAT80"              194  C  "Hitachi 250GB"

Make sure, that your temperature is referred in field 194 of the S.M.A.R.T interface and is in degrees celsius otherwise correct the two fields. Read the man page of hddtemp, how to check this.

Install mailto

Just do

$ emerge metamail

Install the checker script

If hddtemp gets you the correct temperature, you need a program to call periodically. Any shell script is sufficient, I add one for reference


DEVICES="/dev/hda /dev/sda"


if [ "$1" == "-d" -o "$1" == "--daemon" ]; then

        while : ; do

                for A in $DEVICES ; do
                        TEMPERATURE=$(hddtemp -n $A)

                        if [ $TEMPERATURE -gt $TEMPLIMIT ] ; then
                                MAILTXT=${MAILTXT}"Device $A has temperature of ${TEMPERATURE}°C (limit ${TEMPLIMIT}°C)\\n"
                        echo $MAILTXT

                if [ -n "$MAILTXT" ] ; then
                        echo "$MAILTXT" | tr '\\n' '\012' | MM_CHARSET=ISO-8859-15 mailto -s "HD temperature warning" $EMAIL_NOTIFIER  > /dev/null
                sleep $CHECK_PERIOD


        for A in $DEVICES ; do
                TEMPERATURE=$(hddtemp -n $A)

                if [ $TEMPERATURE -gt $TEMPLIMIT ] ; then
                        MAILTXT="${MAILTXT}Device $A has temperature of ${TEMPERATURE}°C (limit ${TEMPLIMIT}°C)\\n"


        if [ -n "$MAILTXT" ] ; then
                echo -e "$MAILTXT"


This script can be called from commandline to check the temperature of the harddisks. Make it executable and test it. To test if warnings appear, lower the temperature limit "TEMPLIMIT" to 1.

$ chmod a+x
$ ./
$ ./ -d

If you add the "-d" option, then this script loops forever, but it does not detach from its controlling terminal. This is what the bootscript does.

Install the boot script

This script executes the checker script in the background and puts a PID file. With this script, we can easily start and stop the checker script and install it to the boot process. You need to check the path of your checker script.

Code: /etc/init.d/check_hdd_temp

depend() {
        use mta

start() {
        ebegin "Starting check_hdd_temp"
        start-stop-daemon --start --quiet --background \
                --pidfile /var/run/ --make-pidfile \
                --exec /root/bin/ \
                -- -d
        eend ${?}

stop() {
        ebegin "Stopping check_hdd_temp"
        start-stop-daemon --stop --quiet --pidfile /var/run/ 
        eend ${?}

UPDATE: up to sys-apps/baselayout-1.11.15-r3 the stop routine did not remove the pid file. The stop routine back then read as follows

stop() {
       ebegin "Stopping check_hdd_temp"
       start-stop-daemon --stop --quiet --pidfile /var/run/ \
               && rm /var/run/
       eend ${?}

This is not needed in baselayout-1.12.4 and above.

Start the checker program

/etc/init.d/check_hdd_temp start

and all should be well. Add it to the boot sequence

rc-update add check_hdd_temp default

Alternative: setting hddtemp init script with wmhdplop

After emerging hddtemp you already have an init script called /etc/init.d/hddtemp. You can check it with

$ equery files hddtemp

Include the script in the init process:

$ rc-update add hddtemp default

Define the drives you want to monitor in /etc/conf.d/hddtemp. For example: HDDTEMP_DRIVES="/dev/hda /dev/hdb /dev/hdd"

Start the script for this session (the script will be executed automatically on next boot)

$ /etc/init.d/hddtemp start

If you are using a window manager that accepts dockapps (like WindowMaker), emerge wmhdplop.

$ emerge wmhdplop

Execute wmhdplop telling which drives to monitor ('-d' flag) and to show the temperature ('-t' flag). You can also play with other flags. For example:

$ wmhdplop -d /dev/hda:A -d /dev/hdb:B -d /dev/hdd:D --noswap --smallfont Verdana/7 --56 -t

Alternative 2: View temperature in the webbrowser

You can also view your disks temperatures in your webbrowser. Define the drives you want to monitor in /etc/conf.d/hddtemp. For example: HDDTEMP_DRIVES="/dev/hda /dev/hdb /dev/hdd"

Start the init script:

$ /etc/init.d/hddtemp start

Open http://localhost:7634 in your favorite webbrowser. The output may look a bit confusing. In my case it is:

|/dev/sda|SAMSUNG SP2504C|34|C||/dev/sdb|SAMSUNG SP2504C|38|C||/dev/sdc|SAMSUNG HD400LJ|38|C|

So I have /dev/sda at 34°C, /dev/sdb at 38°C and /dev/sdc at 38°C

Finaly add the script to your autostart:

$ rc-update add hddtemp default


Retrieved from ""

Last modified: Tue, 02 Sep 2008 23:21:00 +0000 Hits: 18,760