-
Notifications
You must be signed in to change notification settings - Fork 4
/
speed
executable file
·75 lines (60 loc) · 1.37 KB
/
speed
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
RXB=0
TXB=0
for rxbytes in /sys/class/net/*/statistics/rx_bytes ; do
let RXB+=$(<$rxbytes)
done
for txbytes in /sys/class/net/*/statistics/tx_bytes ; do
let TXB+=$(<$txbytes)
done
sleep 2
RXBN=0
TXBN=0
for rxbytes in /sys/class/net/*/statistics/rx_bytes ; do
let RXBN+=$(<$rxbytes)
done
for txbytes in /sys/class/net/*/statistics/tx_bytes ; do
let TXBN+=$(<$txbytes)
done
#divide by two for the period, multiply by 10 to allow a correct decimal place
RXDIF=$(echo $(((RXBN - RXB) * 5 )))
TXDIF=$(echo $(((TXBN - TXB) * 5 )))
SPEEDU="^B/s"
SPEEDD="vB/s"
if [ $RXDIF -ge 10240 ]; then
SPEEDD="vKi/s"
RXDIF=$(echo $((RXDIF / 10240 )) )
fi
if [ $TXDIF -ge 10240 ]; then
SPEEDU="vKi/s"
TXDIF=$(echo $((TXDIF / 10240 )) )
fi
if [ $RXDIF -ge 10240 ]; then
SPEEDD="vMi/s"
RXDIF=$(echo $((RXDIF / 10240 )) )
fi
if [ $TXDIF -ge 10240 ]; then
SPEEDU="vMi/s"
TXDIF=$(echo $((TXDIF / 10240 )) )
fi
if [ $RXDIF -ge 10240 ]; then
SPEEDD="vGi/s"
RXDIF=$(echo $((RXDIF / 10240 )) )
fi
if [ $TXDIF -ge 10240 ]; then
SPEEDU="vGi/s"
TXDIF=$(echo $((TXDIF / 10240 )) )
fi
RXDIFF=$(($RXDIF % 10 ))
RXDIFI=$(( $RXDIF / 10 ))
RXDIF="$RXDIFI"
if [ $RXDIFF -ne 0 ]; then
RXDIF=$( echo "$RXDIFI.$RXDIFF" )
fi
TXDIFF=$(($TXDIF % 10 ))
TXDIFI=$(( $TXDIF / 10 ))
TXDIF="$TXDIFI"
if [ $TXDIFF -ne 0 ]; then
TXDIF=$( echo "$TXDIFI.$TXDIFF" )
fi
echo "$RXDIF $SPEEDD $TXDIF $SPEEDU"