0
1
I need to monitor the network activities of a process and the bandwidth of the connection. So I decided to use nethog
and netperf
combine with grep
and awk
to write the values to a file.
nethog
command: nethogs -t eth0 | grep firefox | awk '{ print $3 }'
(I want to take the upload/download speed). The 1st problem is that command doesn't print anything.
More detail:
command: nethogs -t eth0 | grep firefox
output:
usr/lib/firefox/firefox-bi�)/4956/1000 0.338867 0.239063
/usr/lib/firefox/firefox-bi�)/4956/1000 0.543555 0.274219
/usr/lib/firefox/firefox-bi�)/4956/1000 0.794531 0.489844
/usr/lib/firefox/firefox-bi�)/4956/1000 0.794531 0.489844
/usr/lib/firefox/firefox-bi�)/4956/1000 0.749023 0.589844
/usr/lib/firefox/firefox-bi�)/4956/1000 1.30098 3.47617
/usr/lib/firefox/firefox-bi�)/4956/1000 1.90449 8.0127
/usr/lib/firefox/firefox-bi�)/4956/1000 5.31641 25.0033
/usr/lib/firefox/firefox-bi�)/4956/1000 8.60762 42.0176
I want the two values at the bottom right. But as you can see the output ain't consistent (the space), add | awk '{print $3}' most of the time return nothing
. And I can't fix this.
netperf
command: netperf -H 192.168.1.10
and the output is:
Recv Send Send
Socket Socket Message Elapsed
Size Size Size Time Throughput
bytes bytes bytes secs. 10^6bits/sec
524288 524288 262144 10.00 **718.62**
I want to print the value on the bottom right but have no idea how to. That's the 2nd problem => solved by fedorqui!
Can you guys help me out? Any ideas will be appreciated!
Do you get any output of
nethogs
alone? Andnethogs -t eth0
? – fedorqui – 2014-03-07T15:53:02.020Yes, yes I do. But it ain't consistent (the space between columns) so I guess that the reason... I have no idea how to fix it :( – Tiana987642 – 2014-03-07T15:56:33.767
But is what you want to output always the last field from last line? – fedorqui – 2014-03-07T15:57:25.863
Not really, but I try your solution on the first problem and still get nothing :( – Tiana987642 – 2014-03-07T15:59:29.690
Try to give some of the output you get. Otherwise, it is pretty complicated to know what can be the problem and how can we help. – fedorqui – 2014-03-07T16:01:07.390
I will update the question. Please wait a few minutes... Thank you! – Tiana987642 – 2014-03-07T16:01:56.640
So you want the values
8.60762 42.0176
? In this case,awk '{print $(NF-1), $NF}'
does it. – fedorqui – 2014-03-07T16:12:20.773It's still return nothing. I really doubt the change of the space between columns :( – Tiana987642 – 2014-03-07T16:15:50.693
And what about checking the answer you were given? – fedorqui – 2014-03-07T15:44:20.097
Your solution works, but the first one still left... – Tiana987642 – 2014-03-07T15:51:34.587
1You never need grep+awk since awk can do anything that grep can do. You need to show some sample output of
nethogs -t eth0
if you want a script that can parse that output as it's input along with the desired output of the tool you want to write. – None – 2014-03-07T17:15:32.173