Getting hard disk temperature

Swobodin's picture
Submitted by Swobodin on Mon, 2006-05-01 12:41. ::
I have found in Linux Gazette an interesting tip to figure out about hard disk temperature, and therefore, to guess about how hot is your computer.
Assuming that smartctl is installed with kernel-utils package, type, as root:
smartctl -a /dev/hda | grep 194
194 Temperature_Celsius     0x0022   035   055   000    Old_age   Always       -       35

Temperature is 35°C, pretty hot!
You may use a shell script to get temperature status
#!/bin/sh
# File: temperature.sh
TEMPC=$(sudo /usr/sbin/smartctl -a /dev/hda | grep 194 | awk '{print $10}') #Temperature in degrees Celcius
echo "$TEMPC C"
TEMPF=$[ $TEMPC*9/5 +32  ] # Convert to degrees Farenheit
echo "Your hard disk temperature is"
echo "$TEMPC C"
echo "$TEMPF F"
if [ $TEMPC -gt 27 ]
    then
        echo "That's not suitable for your hardware, you should make the room colder"
    else
        echo "Temperature is okay"
    fi
unset TEMPC TEMPF

Add the following value to your sudoers file
echo "%users ALL=NOPASSWD:/usr/sbin/smartctl -a /dev/hda" >> /etc/sudoers
Append to group "users" the users you want, in your /etc/group
users:x:100:tester,swobodin,foo,gates
and restrict usage to the group
chgrp users temperature.sh
chmod 754 temperature.sh