Add drive name to smartctl along with drive temperature

Ubuntu Version
24.04.3

I found a nice script to get smartctl to output drive temperatures for the drives in my RAID box, but I’d like to also display my drive names in the output as well.

My script contains this line of code, I apologize if I’ve displayed my code incorrectly:
find /dev/sd? -exec smartctl -a {} \; | grep -i Temperature_Celsius
Which reports back the twelve drives in my ZFS RAID and the boot drive

The output also displays which drives are reporting Old_age for some reason, but I’m okay with that.

Output:

194 Temperature_Celsius     0x0022   026   047   000    Old_age   Always       -       26 (0 14 0 0 0)
194 Temperature_Celsius     0x0022   026   046   000    Old_age   Always       -       26 (0 15 0 0 0)
194 Temperature_Celsius     0x0022   114   084   000    Old_age   Always       -       33
194 Temperature_Celsius     0x0022   071   063   000    Old_age   Always       -       29 (Min/Max 29/37)
194 Temperature_Celsius     0x0022   027   048   000    Old_age   Always       -       27 (0 15 0 0 0)
194 Temperature_Celsius     0x0022   070   059   000    Old_age   Always       -       30 (Min/Max 26/41)
194 Temperature_Celsius     0x0022   026   048   000    Old_age   Always       -       26 (0 14 0 0 0)
194 Temperature_Celsius     0x0022   026   046   000    Old_age   Always       -       26 (0 14 0 0 0)
194 Temperature_Celsius     0x0022   026   047   000    Old_age   Always       -       26 (0 14 0 0 0)
194 Temperature_Celsius     0x0022   027   049   000    Old_age   Always       -       27 (0 15 0 0 0)
194 Temperature_Celsius     0x0022   026   046   000    Old_age   Always       -       26 (0 15 0 0 0)
194 Temperature_Celsius     0x0022   026   046   000    Old_age   Always       -       26 (0 14 0 0 0)
194 Temperature_Celsius     0x0022   027   047   000    Old_age   Always       -       27 (0 15 0 0 0)

I spent time Googling for an answer but with no success. I admit that my scripting skills aren’t particularly good.

I’d appreciate any help I can get.

You can include the drive name in the output by printing the device path before running smartctl.
A simple way is to use echo inside your loop:

Option 1 — Print device name + temperature

for d in /dev/sd?; do
    echo "$d:"
    smartctl -a "$d" | grep -i Temperature_Celsius
    echo
done

Output will look like:

/dev/sda:
194 Temperature_Celsius …  26

/dev/sdb:
194 Temperature_Celsius …  27

Option 2 — One-liner version

find /dev/sd? -exec sh -c 'echo "$1"; smartctl -a "$1" | grep -i Temperature_Celsius' _ {} \;

This way you’ll clearly see which temperature belongs to which drive, without changing your existing smartctl filters.

1 Like

You rock! It’s perfect. Thank you.

I’m glad it worked for you! Happy to help. :blush:

This topic was automatically closed after 30 days. New replies are no longer allowed.