Use Shell to monitor network traffic under Linux

Source: Internet
Author: User

#input the network name if [-N "]; Then Eth_name=$1else eth_name= "eth0" fi send_o= ' ifconfig $eth _name | grep bytes | awk ' {print $6} ' | Awk-f: ' {print $} ' recv_o= ' ifconfig $eth _name | grep bytes | awk ' {print $} ' | Awk-f: ' {print $} ' send_n= $send _orecv_n= $recv _o i=0while [$i-le 100000]; Do send_l= $send _n recv_l= $recv _n sleep 2 send_n= ' ifconfig $eth _name | grep bytes | awk ' {print $6} ' | Awk-f: ' {print $} ' recv_n= ' ifconfig $eth _name | grep bytes | awk ' {print $} ' | Awk-f: ' {print $} ' i= ' expr $i + 1 ' send_r= ' expr $send _n-$send _l ' recv_r= ' expr $recv _n-$recv _l ' Total_    r= ' expr $send _r + $recv _r ' send_ra= ' expr \ ($send _n-$send _o \)/$i ' recv_ra= ' expr \ ($recv _n-$recv _o \)/$i ' Total_ra= ' expr $send _ra + $recv _ra ' sendn= ' ifconfig $eth _name | grep bytes | Awk-f \ (' {print $} ' | awk-f \) ' {print $} ' recvn= ' ifconfig $eth _name | grep bytes | Awk-f \ (' {print $} ' | awk-f \) ' {print $} ' clear Echo ' last Second:send Rate: $send _r bytes/sec Recv rate: $RECV _r bytes/sec Total rate: $total _r bytes/sec "echo" Average value : Send rate: $send _ra bytes/sec Recv rate: $recv _ra bytes/sec all rate: $total _ra bytes/sec "Echoes" Total traffic afte R startup:send Traffic: $sendn RECV traffic: $RECVN "done


Here are some of the common shell commands used:
Whether the variable string is empty
To run the command you need to use the • Application as a command
The basic notation of the while loop
The use of some mathematical expressions
Escape notation for some special symbols of the output

Use Shell to monitor network traffic under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.