Skip to content

Instantly share code, notes, and snippets.

@maxux
Last active July 9, 2023 20:49
Show Gist options
  • Save maxux/e77eeb3e49bdd5acc45bd33a2b856da6 to your computer and use it in GitHub Desktop.
Save maxux/e77eeb3e49bdd5acc45bd33a2b856da6 to your computer and use it in GitHub Desktop.
HDD Temperature over smartctl when hddtemp doesn't works
import subprocess
import sys
import json
drives = [
"/dev/sda",
"/dev/sdb",
"/dev/sdc",
"/dev/sdd",
"/dev/sde",
"/dev/sdf",
"/dev/sdg",
"/dev/sdh",
]
temperatures = {}
sys.stdout.write(f"[+] fetching ")
sys.stdout.flush()
for drive in drives:
sys.stdout.write(".")
sys.stdout.flush()
a = subprocess.run(['smartctl', '-j', '--attributes', drive], capture_output=True)
data = json.loads(a.stdout.decode('utf-8'))
for field in data['ata_smart_attributes']['table']:
if field['id'] == 194:
temperatures[drive] = {"now": field['value'], "worst": field['worst']}
print("")
for disk in temperatures.keys():
value = temperatures[disk]
print(f"[+] {disk}: {value['now']}°C [{value['worst']}°C]")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment