Add cpufantemp.py, hddtemp.py, sysFanTemp.py

This commit is contained in:
2024-03-25 14:38:01 +00:00
parent cf5f43c914
commit 1b136c31d7
4 changed files with 158 additions and 1 deletions

52
hddtemp.py Executable file
View File

@@ -0,0 +1,52 @@
#!/usr/bin/python3
import subprocess
import json
def runCmd(cmdString):
result = subprocess.run(cmdString, stdout=subprocess.PIPE, shell=True).stdout.decode('utf-8')
return result
def findHddId():
hddDict = {}
results = runCmd("blkid").split("\n")
for line in results:
if line == "":
continue
hddInfoList = line.split(" ")
if len(hddInfoList) > 1 and hddInfoList[0].startswith("/dev/sd"):
hddName = hddInfoList[0].replace(":", "")
hddDict[hddName] = {}
for hddInfoline in hddInfoList[1:]:
kvList = hddInfoline.split("=")
if len(kvList) > 1:
hddDict[hddName][kvList[0].replace("\"", "")] = kvList[1].replace("\"", "")
return hddDict
def findHddTemp(hddDict):
for hddName in sorted(hddDict.keys()):
cmd = f"smartctl -A {hddName} | grep Temperature_Celsius"
hddTempString = runCmd(cmd)
hddTempList = hddTempString.split(" ")
hddTempList = [item for item in hddTempList if item != ""]
if len(hddTempList) > 9:
hddDict[hddName]["temp"] = int(hddTempList[9])
def getHddTemp():
hddDict = findHddId()
findHddTemp(hddDict)
return hddDict
def main():
hddDict = getHddTemp()
print(f"{json.dumps(hddDict, indent=4)}")
if __name__ == "__main__":
main()