import re
import subprocess
import time
import json
def get_temperatures(disks):
sensors = subprocess.check_output(["sensors"])
temperatures = {match[0]: float(match[1]) for match in re.findall("^(.*?)\:\s+\+?(.*?)°C",
sensors, re.MULTILINE)}
for disk in disks:
output = subprocess.check_output(["smartctl", "-A", disk])
temperatures[disk] = int(re.search("Temperature.*\s(\d+)\s*(?:\([\d\s]*\)|)$",
output, re.MULTILINE).group(1))
return temperatures
def main():
while True:
print json.dumps(get_temperatures(("/dev/sda2", "/dev/sdb1")))
time.sleep(20)
if __name__ == '__main__':
main()
This is a small script for temperature control in Python using smartmontools and lm sensors. But when I try to run it, I have an error
subprocess.CalledProcessError: Command '['smartctl', '-A', '/dev/sda2']' returned non-zero exit status 2
But when I try to execute this command manually in the terminal, they work fine.
Some information:
uname -a
Linux LME 4.0.0-040000-generi # 201504121935 SMP Sun Apr 12 23:36:33 UTC 2015 x86_64 x86_64 x86_64 GNU / Linux
source
share