释放双眼,带上耳机,听听看~!
代码如下:
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 1#!/bin/bash
2
3while [ "1" ]
4
5do
6
7eth=$1
8
9RXpre=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}')
10
11TXpre=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}')
12
13sleep 1
14
15RXnext=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}')
16
17TXnext=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}')
18
19clear
20
21echo -e "\t RX `date +%k:%M:%S` TX"
22
23RX=$((${RXnext}-${RXpre}))
24
25TX=$((${TXnext}-${TXpre}))
26
27if [[ $RX -lt 1024 ]];then
28
29RX="${RX}B/s"
30
31elif [[ $RX -gt 1048576 ]];then
32
33RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
34
35else
36
37RX=$(echo $RX | awk '{print $1/1024 "KB/s"}')
38
39fi
40
41if [[ $TX -lt 1024 ]];then
42
43TX="${TX}B/s"
44
45elif [[ $TX -gt 1048576 ]];then
46
47TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')
48
49else
50
51TX=$(echo $TX | awk '{print $1/1024 "KB/s"}')
52
53fi
54
55echo -e "$eth \t $RX $TX "
56
57done
58
调用方式:
代码如下:
1
2
3
4
5
6 1./traff.sh eth1
2
3或
4
5bash traff.sh eth1
6
可以实时显示网卡流量大小: