Qball's Weblog
Commandline Logging of data.
Given the high temperatures here currently and the fact I have been playing with DS18s20 temperature sensors connected to my Pandaboard. I decided to setup some ‘long-term’ temperature logging.
Normally I would store the data just in a plaintext file, but for now I am going to put it in a sqlite database. (I want to run it for weeks, but still be fine grained).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#!/bin/bash LOG_FILE=temperature.sql if [ ! -f $LOG_FILE ] then echo "Create database..." sqlite3 $LOG_FILE "create table temperature(time datetime primary key,sensor integer, value real);" fi NOW=$(date +%s) TEMP=$(digitemp_DS9097 -c /etc/digitemp.conf -q -t -o"%C") sqlite3 $LOG_FILE "insert into temperature values('$NOW', '0', '$TEMP');" |
Yes it is this simple! No there is not a lot of error checking, but for things like this, its ok.
Now I call this one every 30 seconds. You can do this with cron, currently I prefer running it in tmux with watch.
1 |
watch -n 30 ./temp_log.sh |
Later I will make posts on how to plot this with gnuplot.