This is easily done in Python. First, learn how to get your CPU's temperature here. Either use the sensors
command or the cat /sys/class/thermal/thermal_zone0/temp
to write the current temperature to a temporary file curr.temperature
. You can do that seperately in a bash script or in the Python program itself, using:
from subprocess import call
call (["/path/to/script/get_temperature"], shell=False)
Then the Python code just needs to read the file curr.temperature
and store the value in a MySQL table. I have not tested this code, but it should be something like this:
#!/usr/bin/python
import MySQLdb.cursors
with open('curr.temperature', 'r') as f:
read_data = f.read()
db = MySQLdb.connect(db='databasename', host='localhost',
port=3306, user='MySQL-username', passwd='password',
cursorclass=MySQLdb.cursors.DictCursor)
cur = db.cursor()
cur.execute("INSERT INTO temperatures VALUES (now," + read_data + ")" )