1

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:

  1. 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)"

  2. 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.

4
  • Huh? You already have the condition that Mon is in the line inside your awk. If you want Tue, just change /Mon/ to /Tue/. Commented Sep 25, 2014 at 12:32
  • Sorry if I'm not being clear, I want to be able to perform if then else, on other stuff too, within the plot line. However I'm struggling to order it like I would a traditional multi-line script as appose to it all being on the same line plot "blar blar blar" Commented Sep 25, 2014 at 15:33
  • 1
    Oh, that's easy. Put all the awk script in a separate file called script.awk - make it as complicated as you like with if statements etc - then use awk -f script.awk Commented Sep 25, 2014 at 15:47
  • 1
    This is a great intro to awk grymoire.com/Unix/Awk.html#uh-2 Commented Sep 25, 2014 at 15:48

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.