01 |
#!/bin/bash |
02 |
while [ "1" ] |
03 |
do |
04 |
eth=$1 |
05 |
RXpre=$( cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}' ) |
06 |
TXpre=$( cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}' ) |
07 |
sleep 1 |
08 |
RXnext=$( cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}' ) |
09 |
TXnext=$( cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}' ) |
10 |
clear |
11 |
echo -e "\t RX `date +%k:%M:%S` TX" |
12 |
RX=$((${RXnext}-${RXpre})) |
13 |
TX=$((${TXnext}-${TXpre})) |
14 |
|
15 |
if [[ $RX - lt 1024 ]]; then |
16 |
RX= "${RX}B/s" |
17 |
elif [[ $RX - gt 1048576 ]]; then |
18 |
RX=$( echo $RX | awk '{print $1/1048576 "MB/s"}' ) |
19 |
else |
20 |
RX=$( echo $RX | awk '{print $1/1024 "KB/s"}' ) |
21 |
fi |
22 |
|
23 |
if [[ $TX - lt 1024 ]]; then |
24 |
TX= "${TX}B/s" |
25 |
elif [[ $TX - gt 1048576 ]]; then |
26 |
TX=$( echo $TX | awk '{print $1/1048576 "MB/s"}' ) |
27 |
else |
28 |
TX=$( echo $TX | awk '{print $1/1024 "KB/s"}' ) |
29 |
fi |
30 |
|
31 |
echo -e "$eth \t $RX $TX " |
32 |
done |