#!/bin/bash
timestep=1;
t=0;
if [ ! -z $1 ]
then
  timestep=$1;
fi

#if [[ ! -p $pipe]]
#  then
rm pipe;
mkfifo pipe;
#fi
 
rm -rf data.txt 2> /dev/null;

echo "$t $(date |cut -d ":" -f 3 | cut -d " " -f 1)" >> data.txt;

echo 'plot "data.txt" w l;' > pipe &

tail -f pipe | gnuplot &

while true
  do
  echo "$t $(date |cut -d ":" -f 3 | cut -d " " -f 1)" >> data.txt;
  echo 'replot;reread;' > pipe
  ((t++));
  sleep $timestep;
done