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
Best Answer
Based solely on your posted
iperf
output, you would simply print fields 3 and 4 from the last line: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 address10.0.0.1
-t 3600
keeps running for3600
seconds, i.e. 1 hour-i 2
prints a report every2
secondsDuring the next hour, a line like this is printed (added) on screen every two seconds:
What you want is reduce the information printed on screen every two seconds, to lines of the form:
Answer: To obtain this, you pipe the output to
awk
: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
:Answer:
Note that this option was added to
iperf3
version3.1.5
.