#!/bin/sh # # Extract hourly average temperature readings from an RRD file # and draw them in a colour graph of days x hours # # Usage: # thermosquare.sh [ [ ] ] # # So if we run it with no arguments we update the current month # # Chris Gillings 2007 # MONTH=`date '+%m'` YEAR=`date '+%Y'` CYEAR=$YEAR if [ "z$1" != "z" ]; then MONTH=$1 fi if [ "z$2" != "z" ]; then YEAR=$2 fi # If I was fussed I'd add in a Leap Year calculation here case $MONTH in (04|06|09|11) DAYS=30;; (02) DAYS=28;; (*) DAYS=31;; esac # we have yearly backups of the RRD file RRDFILE=airtemp.rrd.0.$YEAR # if it's this year we take a fresh copy of the active file if [ $YEAR == $CYEAR ]; then cp /var/lib/rrd/sys/airtemp.rrd.0 airtemp.rrd.0.$YEAR fi # extract hourly stats for this month into a plain text file rrdtool xport --start "00:00 ${YEAR}${MONTH}01" --end "23:00 ${YEAR}${MONTH}${DAYS}" DEF:xx=${RRDFILE}:t:AVERAGE:step=3600 XPORT:xx:"Temp" | grep "" | sed 's#^.*##g' | sed 's# ${YEAR}${MONTH}.vals # (re)generate the graph for this month php thermosquare.php month=${YEAR}${MONTH} # that's all