Sample Header Ad - 728x90

Using awk and grep for iftop results

1 vote
2 answers
4549 views
I wanted to monitor my server network send and receive rate using iftop. This is what works for me: iftop -t -s 1 -n -N | grep 'Total send and receive rate: ' | awk '{print $8}' Mac address and Ips are included in the result, something like this: interface: eth0 IP address is: 192.254.78.90 MAC address is: 00:26:9e:b5:81:de 14.7Mb I only need the last line. So I created a script: iftop -t -s 1 -n -N >> result.txt cat result.txt | grep 'Total send and receive rate: ' | awk '{print $8}' When I use this in command line it works fine and give me only the last line which is "14.7Mb" while using it as a .sh script still includes the MAC address and Ip. Any idea how can resolve? I think there should be a better solution using sed ?
Asked by Amin (151 rep)
Nov 17, 2015, 07:35 AM
Last activity: Feb 12, 2018, 11:57 AM