6 Reads 'sensors -u' for temperature data. Writes all temperatures found
7 to stdout. One temp per line, preceded by the unix UTC time in seconds,
10 Before you can use this utility lm_sensors must be installed and
11 configured. See their documentation for that procedure.
13 How many temperatures, which temeratures and in which order will depend
14 on your lm_sensors configuration and your motherboard.
16 Sample log from an Supermicro Quad Core Xeon:
25 Field 1: unix time in seconds since the star of the epoch
26 Field 2: Log source (LM)
27 Field 3: temperature in degrees C
31 # take and log cpu temp every 5 mins
32 */5 * * * * /usr/local/sbin/cpu-temp-log >> /var/log/ntpstats/temps
34 This file may only be useful as a template. The way to read your system
35 temperatures will be hardware specific.
39 from __future__
import print_function
, division
47 # sadly subprocess.check_output() is not in Python 2.6
48 proc
= subprocess
.Popen(["sensors", "-u"],
49 stdout
=subprocess
.PIPE
,
50 stderr
=subprocess
.STDOUT
,
51 universal_newlines
=True)
52 output
= proc
.communicate()[0]
54 print("Unable to run 'sensors -u'")
57 lines
= output
.split('\n')
59 # this regex matches temperature output lines from 'sensors -u'
60 pat
= re
.compile(r
'^\s+temp\d+_input:\s+([\d\.]+).*$')
62 now
= int(time
.time())
67 match
= pat
.match(line
)
68 if match
and match
.group(1):
70 sys
.stdout
.write('%d LM%d %s\n' % (now
, index
, temp
))