Last active
July 9, 2023 20:49
-
-
Save maxux/e77eeb3e49bdd5acc45bd33a2b856da6 to your computer and use it in GitHub Desktop.
HDD Temperature over smartctl when hddtemp doesn't works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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