#!/bin/bash

NUMBER_OF_RECORDS=8000
LOGFILE=/var/log/power.log

TEMPNAME=`mktemp`

echo -en "Content-type: image/png\n\n"


tail -n $NUMBER_OF_RECORDS $LOGFILE > $TEMPNAME

/usr/bin/gnuplot << ENDOFINPUT
set terminal png
set xdata time
set timefmt "%m/%d/%y"
set format x "%m/%d %H:%M"
set timefmt "%m/%d/%y %H:%M:%S"
set title "Power Plot"
set xlabel "Time/Date"
set ylabel "Watts"
set grid
set xtics rotate
plot "$TEMPNAME" using 1:3 title "CH1" with lines, \
"$TEMPNAME" using 1:4 title "CH2" with lines, \
"$TEMPNAME" using 1:5 title "CH3" with lines
ENDOFINPUT

#set yrange [50:5000]


rm $TEMPNAME
