Reputation: 181
I've managed to get a graph automatically plotted from live data on my system, using a gpuplot script, piping the raw data through awk. The script command.gpl is below:
#------------------------run this file--------------------
#gnuplot /usr/src/scripts/plots/core_temp_data/command.gpl
#---------------------------------------------------------
set terminal png size 2100,1000
set output '/usr/src/scripts/plots/core_temp_data/output_sat.png'
set title "Core Temp versus Time"
set size ratio 0.4
set xdata time
set timefmt "%H:%M"
set format x "%H:%M"
plot "<awk '/Mon/{print $4, substr($0,match($0,/temp=[0-9.]+/)+5,RLENGTH-5)}' /var/log/rebootlogfile.log" using 1:2 with points # works
I would like to be able to:
Add variables to make the plot line more readable
eg.
condition="/Mon/"
and action="print $4,substr($0,match($0,/temp=[0-9.]+/)+5,RLENGTH-5)"
Apply if then conditions to it
eg
if the record starts with Mon then plot "plot code for Mon"
or if the record starts with Tue then plot "plot code for Tue"
However, each time I try and separate the plot line I get syntax errors.
Can I do these things, if so how?
This is a link to my previous post with how I got to this stage.
Upvotes: 1
Views: 1004
Reputation: 74705
At the moment your question is a bit too broad and I think you should decide on a specific problem you would like to solve. It sounds like you might benefit from using sprintf
in gnuplot to build your command string. For example:
condition = "/Mon/"
action = "print $4,substr($0,match($0,/temp=[0-9.]+/)+5,RLENGTH-5)"
file = "/path/to/file"
cmd = sprintf("<awk '%s {%s}' %s", condition, action, file)
plot cmd with points
Upvotes: 2