#!/usr/bin/python # # myth_sensors.py # Retrieves sensors output and formats it for inclusion in the MythTV backend # status page. # Prerequisites: # install: hddtemp +(allow sudo hddtemp), lm-sensors, python n' stuff # run: sensors-detect # run: sensors and use that info to update the list of sensors names below. import re import glob import commands # Set this list of sensors to match what you want to track. Run "sensors" to # see a list of everything that's available on your system. The left side # of this list is text that will be on the status page and the right is what # needs to match the output of "sensors" SensorNames = {'CPU0 Temp :':"Core 0:", 'CPU1 Temp :':"Core 1:", 'Fan Speed (CPU):':"CPU:", 'Fan Speed (Sys):':"System:"} # Set the following dictionary to name whatever drives (/dev/sd?) you have in # your system (or else live with the names I use) DriveNames = {'/dev/sda':"OS Drive ", '/dev/sdb':"Media ", '/dev/sdc':"Backup #1", '/dev/sdd':"Backup #2", '/dev/sd?':"Your name"} # You shouldn't need to modify anything below here. print "Current Temperatures and fan speeds:" (sensors_status,sensors_output) = commands.getstatusoutput('sensors') sortedSensorNames = SensorNames.keys() sortedSensorNames.sort() if sensors_status == 0: for patterns in sortedSensorNames: sensorPat = re.compile('^'+SensorNames[patterns]+'\s+\+*(\d{1,4})(\.\d*..C|\sRPM)', re.M) sensorData = sensorPat.search(sensors_output) if sensorData: if re.search(r'RPM',patterns): suffix=" RPM" else: suffix="°C" print patterns+" "+sensorData.group(1)+suffix (hddtemp_status,hddtemp_output) = commands.getstatusoutput('sudo hddtemp /dev/sd?') if hddtemp_status == 0: driveList = glob.glob('/dev/sd?') for drive in sorted(driveList): drivePat = re.compile(drive+':.*:\s+(\d{1,3})..C$', re.M) driveTemp = drivePat.search(hddtemp_output) if driveTemp: if drive in DriveNames: CurrentDriveName=DriveNames[drive] else: CurrentDriveName="Unknown " print CurrentDriveName+" Temp : "+driveTemp.group(1)+"°C"