3

I have a logfile with the following data in it:

Sat Sep 20 11:25:01 BST 2014 -- temp=53.0'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 20 11:26:01 BST 2014 -- temp=53.0'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 20 11:27:01 BST 2014 -- temp=53.0'C -- message from script /usr/src/scripts/wifi_test_2.sh

There are many more logs but I've shown only 3.

I have a script with the following commands in it, but the data is not in the correct format for GNUplot to work.

SCRIPT:

set terminal png size 400,300
set output '/usr/src/scripts/plots/core_temp_data/output.png'
plot "/var/log/rebootlogfile.log" using 4:8 with lines

Is it possible to plot 11:25:01 against 53.0 with a gnu command,or gnu and awk, or do I have to strip out the log file of unnecessary data?

  • I don't use gnuplot but the error seems pretty clear: plot: command not found. Are you sure the command you're looking for is plot? – terdon Sep 23 '14 at 12:59
  • What? That's a completely different error. – terdon Sep 23 '14 at 13:22
  • You can see how to plot time data in gnuplot here: gnuplot.sourceforge.net/demo/timedat.html. You can also see how to parse the timestamp and convert it to the format that gnuplot accepts here: gnu.org/software/gawk/manual/html_node/Time-Functions.html. You can also use an awk script in gnuplot using this syntax: plot "<awk '{commands;}' file" using ... Placing them all together is just coding. – user000001 Sep 23 '14 at 18:08
  • I like the first example in the first link, but to understand it I need the raw data, and how it's presented in the file timedat.dat. Do you know where I can get this from? Also the last example is interesting, but I need a few working "commands" examples to see how they work. I'm looking for "awk commands" that manipulate "text=number" and plot just the number when it recognizes "text=" – reggie Sep 23 '14 at 21:19
1

There may be better ways to do this, but the following accurately generated a graph based on the data, with string values on the time axis.

#Process log data into compatible format. plotdata is Just a copy/paste of your sample data
awk -F" -- " '{print $2,$1}' plotdata | while read temp date; do echo $(date --date="$date" '+%R') $(echo $temp | grep -o "[0-9\.]*"); done > plotdataout; 
#Run the script on the converted data
gnuplot gnuplotscript

Then below is the gnuplot script with string labels:

set term png 
set output "plotdata.png"
set title "Temp Data"
set xlabel "Time (s)"
set ylabel "Temp (F)"
set grid
plot "plotdataout" using 2:xticlabels(1) with lines

Output image

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.