-
Notifications
You must be signed in to change notification settings - Fork 0
/
bw.sh
executable file
·58 lines (46 loc) · 1.03 KB
/
bw.sh
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# John F. Davis
# Tools Group
shopt -s extglob
# parameter one is the interface
interface=$1
if [ -z $interface ]; then
echo "usage: $0 <eth0|eth1>"
exit 1
fi
#echo interface is $interface
RxOld=1
TxOld=1
while true;
do
sleep 1;
ctr=0;
myarray[0]=0;
myarray[1]=0;
# find the tokens in the ifconfig output.
# it will find RX bytes first and then TX bytes
for mytoken in $(ifconfig "$interface")
do
if [[ $mytoken =~ bytes:+([0-9]) ]]; then
# find the token which is bytes:xxxxx
#echo $mytoken
mybytes=${mytoken##bytes:}
# extract the byte count
#echo $mybytes
myarray[ctr]=$mybytes
ctr=$ctr+1
fi
done
# echo ${myarray[0]}
# echo ${myarray[1]}
# break
RxNew=${myarray[0]}
TxNew=${myarray[1]}
RxBPS=`expr $RxNew - $RxOld`
TxBPS=`expr $TxNew - $TxOld`
# if you want to run raw bytes per second
#echo "Rx Bytes per second" $RxBPS " Tx Bytes per second" $TxBPS
echo "Rx Bytes per second" `./mycalc.sh $RxBPS` " Tx Bytes per second" `./mycalc.sh $TxBPS`
RxOld=$RxNew
TxOld=$TxNew
done