Search code examples
awkgnuplot

adding conditions to a gnuplot awk script


With lots of help from the community I have managed to get a graph from rebootlogfile.log into a graph using the script below

command.gpl

 set terminal png size 2000,600
    set output '/usr/src/scripts/plots/core_temp_data/output.png'


    set size ratio 0.4
    set xdata time
    set timefmt "%H:%M:%S"

    plot "<awk '{print $4, substr($0,match($0,/temp=[0-9.]+/)+5,RLENGTH-5)}' /var/log/rebootlogfile.log" using 1:2 with lines

I run the script from shell using

gnuplot /usr/src/scripts/plots/core_temp_data/command.gpl

which gives me enter image description here

the data is a huge file which looks like below but with many more lines over multiple days not just Sat as printed here:

Sat Sep 20 18:10:02 BST 2014 -- temp=57.3'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 20 18:11:01 BST 2014 -- temp=57.3'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 20 18:12:01 BST 2014 -- temp=57.8'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 20 18:13:01 BST 2014 -- temp=57.3'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 20 18:14:02 BST 2014 -- temp=58.4'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 20 18:15:01 BST 2014 -- temp=57.8'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 20 18:16:01 BST 2014 -- temp=57.3'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 20 18:16:02 BST 2014 -- WiFi seems stuck, rebooting - message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 20 18:17:18 BST 2014 -- temp=57.3'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 20 18:18:02 BST 2014 -- temp=58.4'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 20 18:19:01 BST 2014 -- temp=58.4'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 20 18:20:01 BST 2014 -- temp=58.9'C -- message from script /usr/src/scripts/wifi_test_2.sh
  1. How can modify the awk command to just print out say "sun"? I've had a go at modifying the if statement question 1 here, but I get syntax errors.

  2. How can I plot on a third column a zero or a black line, or something to identify "wifi seems stuck"

  3. this is what I'm after (24 hrs of Mon 22) taken from a spreadsheet chart on the data:

  4. I was thinking about something like this:

    plot "<awk 'if ($1 == 'Sat') {print $4, substr($0,match($0,/temp=[0-9.]+/)+5,RLENGTH-5)}' /var/log/rebootlogfile.log" using 1:2 with points

    but when I run it I get x range is invalid.


Solution

  • Thanks to andyras for pointing me in the correct direction. I was trying to grep a column that wasn't being outputted from the awk command. After further searching I stumbled on conditions in awk and bingo! This command worked!

    plot "<awk '/Mon/ {print $4, substr($0,match($0,/temp=[0-9.]+/)+5,RLENGTH-5)}' /var/log/rebootlogfile.log" using 1:2 with points

    enter image description here