Skip to content

Instantly share code, notes, and snippets.

@alexpirine
Last active December 20, 2015 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexpirine/6151556 to your computer and use it in GitHub Desktop.
Save alexpirine/6151556 to your computer and use it in GitHub Desktop.
Trivial server temperature logger using lm-sensors in python
# coding: utf-8
import re
import subprocess
import time
LOG_FILE = '/var/log/temperature.csv'
res = subprocess.check_output(['sensors'])
res = re.findall(r':\s+\+(\d\d\.\d)°C', res)
res = sum([float(value) for value in res]) / len(res)
res = '%(date)d,%(temperature).2f\n' % {
'date': time.time(),
'temperature': res,
}
f = open(LOG_FILE, 'a')
f.write(res)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment