Quick and dirty script to show disk temps in Linux
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
Leave Quick and dirty script to show disk temps in Linux to:
Read more #script posts
Best Posts From ATeXoras
We have not curated any of atexoras's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From ATeXoras
- Quick and dirty script to show disk temps in Linux
- That Finnaly Awaited ATX GitBook 😎
- Diesel Pool Creation - Guide
- HE-AWM 1.3.0 - Hive-Engine Auto Witness Monitor
- MongoDB Restore performance analysis (part 1/3) - ZFS Filesystem on HDD
- HE-AWM 1.2.6 - Hive-Engine Auto Witness Monitor (release + update)
- LVM Snapshots - Going surprisingly great!
- Minor updates to HE-AWM and recipe for LVM based Snapshots
- Minor updates to HE-AWM and recipe for LVM based Snapshots
- HE-AWM 1.2.0 - Hive-Engine Auto Witness Monitor