1

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.

3 Answers 3

1

You could add a pipe to grep for "Sun":

plot '< (awk stuff) | grep "^Sun"' using 1:2 ...

The ^ matches the beginning of a line.

Sign up to request clarification or add additional context in comments.

7 Comments

plot "<awk '{print $4, substr($0,match($0,/temp=[0-9.]+/)+5,RLENGTH-5)}' /var/log/rebootlogfile.log | grep '^Sun'" using 1:2 with lines didn't work is it to do with " and '
Maybe--grepping that pattern works with both single and double quotes on my system (Mac OS X). What happens when you run that command on the command line rather than through gnuplot? "didn't work" is not very descriptive; it is better to show how it fails.
Sorry about the lack of error messages: line 17: warning: Skipping data file with no valid points and line 17: x range is invalid when I try and run the whole thing; and nothing happens in the command line, it just doesn't return to the prompt.
What happens when you run grep without the ^ character? Still nothing?
is it not something to do with " & ' and how they are used? I cannot find any syntax examples like this one to check.
|
0

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

Comments

0

Just for completeness. You could also do it with gnuplot only and in addition platform-independently. No need for awk.

Use the ternary operator and string operators to filter your data in gnuplot. Check help ternary. The example below will filter Saturdays, i.e. plot only data with Sat in the first column.

Data: SO26019396.dat (your data, slightly modified for illustration)

Sat Sep 10 00:10:02 BST 2014 -- temp=57.3'C -- message from script /usr/src/scripts/wifi_test_2.sh
Tue Sep 13 12:11:01 BST 2014 -- temp=57.3'C -- message from script /usr/src/scripts/wifi_test_2.sh
Wed Sep 14 13:12:01 BST 2014 -- temp=57.8'C -- message from script /usr/src/scripts/wifi_test_2.sh
Thu Sep 15 14:13:01 BST 2014 -- temp=57.3'C -- message from script /usr/src/scripts/wifi_test_2.sh
Fri Sep 16 15:14:02 BST 2014 -- temp=58.4'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 17 16:15:01 BST 2014 -- temp=57.8'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sun Sep 18 17:16:01 BST 2014 -- temp=57.3'C -- message from script /usr/src/scripts/wifi_test_2.sh
Mon Sep 19 18:16:02 BST 2014 -- WiFi seems stuck, rebooting - message from script /usr/src/scripts/wifi_test_2.sh
Sat Sep 24 19:17:18 BST 2014 -- temp=57.3'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sun Sep 25 20:18:02 BST 2014 -- temp=58.4'C -- message from script /usr/src/scripts/wifi_test_2.sh
Tue Sep 27 21:19:01 BST 2014 -- temp=58.4'C -- message from script /usr/src/scripts/wifi_test_2.sh
Sat Oct 01 22:20:01 BST 2014 -- temp=58.9'C -- message from script /usr/src/scripts/wifi_test_2.sh

Script: (works with gnuplot>=4.6.0, March 2012)

### filter data (gnuplot>=4.6.0)
reset

FILE = "SO26019396.dat"

myTime(col)  = strcol(col) eq "Sat" ? timecolumn(4) : NaN
myValue(col) = (_s=strcol(col), _s[1:5] eq "temp=" ? real(_s[6:]) : NaN)

set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M"

plot FILE u (myTime(1)):(myValue(8)) w p pt 7 lc rgb "red" notitle
### end of script

Script: (works with gnuplot>=5.0.0, Jan. 2015)

### filter data (gnuplot>=5.0.0)
reset session

FILE = "SO26019396.dat"

myTime(col)  = strcol(col) eq "Sat" ? timecolumn(4,"%H:%M:%S") : NaN
myValue(col) = (_s=strcol(col), _s[1:5] eq "temp=" ? real(_s[6:]) : NaN)

set format x "%H:%M" timedate

plot FILE u (myTime(1)):(myValue(8)) w p pt 7 lc rgb "red" notitle
### end of script

Result:

enter image description here

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.