Quick and dirty script to show disk temps in Linux

in #script9 months ago (edited)

While going through some useless ways of not finding software that shows me any good overall "summary" of a good source of temperatures from devices on Linux... I did something quick and dirty... unsure if this is useful, but for me its quite...

#!/bin/bash
# Author: forykw
# Date: 2024/03/13

# Get all devices
DEVICES=`lsscsi | rev | tr -s " " | awk '{print $1}' | rev`

# Loop the temperature lines
for i in `echo ${DEVICES}`
do
        # Read the 'for' loop 'per line' instead of per 'space'
        IFS=$'\n'
        # First grep is what you want to target from temperature outputs and the second grep is what you want to ignore from some settings (example configs and settings about warnings)
        for j in `smartctl -a $i | grep -i temperature | grep -vi -e critical -e warning`
        do
                # Customizable output in case you need to drop more context in a per device output "found" line
                echo "[$i]: "$j
        done
done

Copy the above into (for example) a file named hdd_temps.sh and then chmod +x hdd_temps.sh and then run it.

Recall this needs the following commands to be available, so test first if you have them installed:

  • lsscsi
  • smartctl

Depending on the system you can find online how to get these. But in Ubuntu it's a simple:

apt install -y lsscsi smartmontools

I needed this for some local "safeguards"... hence why...

Leave you with an example of how the output looks like:

./hdd_temp.sh
[/dev/sdc]: Current Drive Temperature:     34 C
[/dev/sdc]: Drive Trip Temperature:        65 C
[/dev/sdd]: Current Drive Temperature:     31 C
[/dev/sdd]: Drive Trip Temperature:        65 C
[/dev/sda]: 190 Airflow_Temperature_Cel 0x0032   041   100   000    Old_age   Always       -       41 (Min/Max -21/70)
[/dev/sda]: 194 Temperature_Celsius     0x0032   041   100   000    Old_age   Always       -       41 (Min/Max -21/70)
[/dev/sdb]: 194 Temperature_Celsius     0x0002   166   166   000    Old_age   Always       -       36 (Min/Max 17/46)
[/dev/sde]: 194 Temperature_Celsius     0x0002   157   157   000    Old_age   Always       -       38 (Min/Max 16/45)
[/dev/sdf]: 194 Temperature_Celsius     0x0002   162   162   000    Old_age   Always       -       37 (Min/Max 17/46)
[/dev/sdg]: 194 Temperature_Celsius     0x0002   157   157   000    Old_age   Always       -       38 (Min/Max 15/46)
[/dev/sdh]: 194 Temperature_Celsius     0x0002   153   153   000    Old_age   Always       -       39 (Min/Max 17/48)
[/dev/sdi]: 194 Temperature_Celsius     0x0002   153   153   000    Old_age   Always       -       39 (Min/Max 17/47)
[/dev/sdj]: 194 Temperature_Celsius     0x0002   153   153   000    Old_age   Always       -       39 (Min/Max 17/48)
[/dev/sdk]: 194 Temperature_Celsius     0x0002   166   166   000    Old_age   Always       -       36 (Min/Max 18/46)
[/dev/sdl]: 194 Temperature_Celsius     0x0002   162   162   000    Old_age   Always       -       37 (Min/Max 17/44)
[/dev/sdm]: 194 Temperature_Celsius     0x0002   157   157   000    Old_age   Always       -       38 (Min/Max 17/46)
[/dev/sdn]: 194 Temperature_Celsius     0x0002   166   166   000    Old_age   Always       -       36 (Min/Max 17/42)
[/dev/sdo]: 194 Temperature_Celsius     0x0002   157   157   000    Old_age   Always       -       38 (Min/Max 17/44)
[/dev/nvme0n1]: Temperature:                        43 Celsius
[/dev/nvme0n1]: Temperature Sensor 1:               43 Celsius
[/dev/nvme0n1]: Temperature Sensor 2:               53 Celsius
[/dev/nvme1n1]: Temperature:                        42 Celsius
[/dev/nvme1n1]: Temperature Sensor 1:               42 Celsius
[/dev/nvme1n1]: Temperature Sensor 2:               53 Celsius

image.png

Sort:  

Congratulations @atexoras! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You published more than 20 posts.
Your next target is to reach 30 posts.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!