Last active
December 13, 2022 23:58
-
-
Save zhiyb/413f142afe9e4e30d0752f1d52b09fd4 to your computer and use it in GitHub Desktop.
Collect all HDD temperatures through drivetemp and output highest temperature for fancontrol
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| import subprocess, time, os | |
| import json | |
| sleep = 10 | |
| outfile = "/tmp/hddtemp_input" | |
| tmpfile = f"{outfile}.tmp" | |
| while True: | |
| proc = subprocess.run(["sensors", "-j", "drivetemp-scsi-*-*"], capture_output=True) | |
| stdout = proc.stdout.decode("ascii") | |
| sensors = json.loads(stdout) | |
| max_temp = 0 | |
| for _,s in sensors.items(): | |
| for k,v in s.items(): | |
| if k.startswith("temp"): | |
| max_temp = max(max_temp, v[f"{k}_input"]) | |
| print(max_temp) | |
| int_temp = round(max_temp * 1000) | |
| with open(tmpfile, "w") as f: | |
| f.write(f"{int_temp}\n") | |
| os.replace(tmpfile, outfile) | |
| time.sleep(sleep) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment