#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