Depending on your server room conditions it may be important to be informed about the hard drive temperatures inside of your servers. System administrators may use Bash and cron to write a simple script that can alert them about sudden temperature change. Various command line tools such as
hddtemp can check your HDD temperature and be used inside of a Bash script.
In this tutorial, you will see how to get the temperature of a hard drive disk on a Linux system. The installation instructions and command examples below will get you started.
In this tutorial you will learn:
- How to install
- How to use
inxito get HDD temperature
- How to use
hddtempto get HDD temperature
- How to write an HDD temperature monitoring Bash script
|Requirements, Conventions or Software Version Used
|Any Linux distro
|Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to install HDD temperature tools in Linux
The tools we will be using are not usually included by default on most Linux distros. You can use the appropriate command below to install inxi and hddtemp with your system’s package manager.
$ sudo apt install inxi hddtemp
$ sudo dnf install inxi hddtemp
$ sudo pacman -S inxi hddtemp
Get HDD temperature command line examples
First, you can determine the path of your block devices by using commands like
$ sudo fdisk -l OR $ lsscsi -g
Hard drives will have a path in the format of
/dev/sdX for example.
- Using the
inxitool now we can determine the temperature of all hard drives with the following command.
$ sudo 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 hard drive temperature of
/dev/sdais 35C. Note that the above command needs to be run with root administrative privileges.
- Or to check the temperature of a specific block device, just specify that device in your command. For example, this command checks the temperature of
$ sudo inxi -xD /dev/sdb
- The same information can be achieved through the
hddtempcommand. Here is how to use it.
$ sudo hddtemp /dev/sda /dev/sda: HTS721060G9SA00: 36°C
Get HDD temperature Bash script
If your intention is to wire a monitoring script to regularly check hard drive’s temperature, you can 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"
In this tutorial, you saw how to get the temperature of a hard drive disk on a Linux system. This is facilitated by the
hddtemp commands, which can easily be installed via package manager on major Linux distros. You also learned how to adapt these commands into a Bash script to regularly monitor HDD temperature and report any major temperature spikes.