-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbandwidth.sh
More file actions
34 lines (32 loc) · 1.05 KB
/
bandwidth.sh
File metadata and controls
34 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
INTERVAL="1" # update interval in seconds
if [ -z "$1" ]; then
echo
echo usage: $0 [interface]
echo
echo e.g. $0 eth0
echo
exit
fi
IF=$1
while true
do
R1=`cat /sys/class/net/$1/statistics/rx_bytes`
T1=`cat /sys/class/net/$1/statistics/tx_bytes`
RD1=`cat /sys/class/net/$1/statistics/rx_dropped`
TD1=`cat /sys/class/net/$1/statistics/tx_dropped`
sleep $INTERVAL
R2=`cat /sys/class/net/$1/statistics/rx_bytes`
T2=`cat /sys/class/net/$1/statistics/tx_bytes`
RD2=`cat /sys/class/net/$1/statistics/rx_dropped`
TD2=`cat /sys/class/net/$1/statistics/tx_dropped`
RBPS=`expr $R2 - $R1`
TBPS=`expr $T2 - $T1`
TMBPS=`expr $TBPS / 1048576`
RMBPS=`expr $RBPS / 1048576`
RDBPS=`expr $RD2 - $RD1`
TDBPS=`expr $TD2 - $TD1`
TDMBPS=`expr $TDBPS / 1048576`
RDMBPS=`expr $RDBPS / 1048576`
echo "TX $1: $TMBPS MB/s RX $1: $RMBPS MB/s, TXDropped : $TDMBPS MB/s, RXDropped: $RDMBPS MB/s"
done