Copy Code code as follows:
#!/bin/bash
While ["1"]
Todo
Eth=$1
rxpre=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ')
txpre=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ')
Sleep 1
rxnext=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ')
txnext=$ (Cat/proc/net/dev | grep $eth | tr: "" | awk ' {print $} ')
Clear
Echo-e "\ t RX ' date +%k:%m:%s ' TX"
rx=$ ((${rxnext}-${rxpre}))
tx=$ ((${txnext}-${txpre}))
if [[$RX-lt 1024]];then
rx= "${RX}B/S"
elif [[$RX-gt 1048576]];then
rx=$ (echo $RX | awk ' {print $1/1048576 ' MB/S "} ')
Else
rx=$ (echo $RX | awk ' {print $1/1024 ' kb/s '} ')
Fi
if [[$TX-lt 1024]];then
tx= "${TX}B/S"
elif [[$TX-gt 1048576]];then
tx=$ (echo $TX | awk ' {print $1/1048576 ' MB/S "} ')
Else
tx=$ (echo $TX | awk ' {print $1/1024 ' kb/s '} ')
Fi
Echo-e "$eth \ t $RX $TX"
Done
Call Mode:
Copy Code code as follows:
./traff.sh eth1
Or
Bash traff.sh eth1
can display the network card traffic size in real time: