1

I am trying to get the output from the command

iperf -c 10.0.0.1 -t 3600 -i 2  

And only need the Interval and bandwidth fields listed for the entire hour of logging.

I haven't used grep or awk in years upon years.

Help would be awesome!

Sample Output:

------------------------------------------------------------
Client connecting to node2, TCP port 5001
TCP window size:  129 KByte (WARNING: requested  130 KByte)
------------------------------------------------------------
[  3] local <IP Addr node1> port 2530 connected with <IP Addr node2> port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  19.7 MBytes  15.8 Mbits/sec

Desired Output:

0.0-10.0 15.8

1 Answer 1

1

Based solely on your posted iperf output, you would simply print fields 3 and 4 from the last line:

| awk 'END{print $3" "$7}'

BUT this question is not simply about awk.

Question: Let's start by explaining what your iperf command does, for the benefit of those who are not familiar with it.

  • -c 10.0.0.1 connects to server listening at address 10.0.0.1
  • -t 3600 keeps running for 3600 seconds, i.e. 1 hour
  • -i 2 prints a report every 2 seconds

During the next hour, a line like this is printed (added) on screen every two seconds:

[  3]  0.0-10.0 sec  19.7 MBytes  15.8 Mbits/sec

What you want is reduce the information printed on screen every two seconds, to lines of the form:

0.0-10.0 15.8

Answer: To obtain this, you pipe the output to awk:

iperf -c 10.0.0.1 -t 3600 -i 2 | awk '/[0-9]]/{sub(/.*]/,"");print $1" "$5}'

You can stop reading here if you employ iperf, i.e. iperf 2.


If you use iperf3, you should have found out by now that the piped output gets buffered. This means you do not see a new line printed on screen every two seconds! Instead, a whole bunch of lines gets printed every 50 seconds or so, depending on the system. Note that this does not happen with iperf 2 because it flushes the output after printing each line.

To have a line of the desired form printed on screen at the desired interval, you need --forceflush:

   --forceflush
          force flushing output at every interval.  Used to avoid  buffer-
          ing when sending output to pipe.

Answer:

iperf3 -c 10.0.0.1 -t 3600 -i 2 --forceflush | awk '/[0-9]]/{sub(/.*]/,"");print}'

Note that this option was added to iperf3 version 3.1.5.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .