宅鸟在工作中有时需要查看指定网卡流量状况,这里分享一个脚本(该脚本非宅鸟所写,忘记作者出处):
直接上脚本:
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
|
#!/bin/bash
while
[
"1"
]
do
eth=$1
RXpre=$(
cat
/proc/net/dev
|
grep
$eth |
tr
:
" "
|
awk
'{print $2}'
)
TXpre=$(
cat
/proc/net/dev
|
grep
$eth |
tr
:
" "
|
awk
'{print $10}'
)
sleep
1
RXnext=$(
cat
/proc/net/dev
|
grep
$eth |
tr
:
" "
|
awk
'{print $2}'
)
TXnext=$(
cat
/proc/net/dev
|
grep
$eth |
tr
:
" "
|
awk
'{print $10}'
)
clear
echo
-e
"\t RX `date +%k:%M:%S` TX"
RX=$((${RXnext}-${RXpre}))
TX=$((${TXnext}-${TXpre}))
if
[[ $RX -lt 1024 ]];
then
RX=
"${RX}B/s"
elif
[[ $RX -gt 1048576 ]];
then
RX=$(
echo
$RX |
awk
'{print $1/1048576 "MB/s"}'
)
else
RX=$(
echo
$RX |
awk
'{print $1/1024 "KB/s"}'
)
fi
if
[[ $TX -lt 1024 ]];
then
TX=
"${TX}B/s"
elif
[[ $TX -gt 1048576 ]];
then
TX=$(
echo
$TX |
awk
'{print $1/1048576 "MB/s"}'
)
else
TX=$(
echo
$TX |
awk
'{print $1/1024 "KB/s"}'
)
fi
echo
-e
"$eth \t $RX $TX "
done
|
调用方式:
1
2
3
|
.
/traff
.sh eth1
或
bash
traff.sh eth1
|
可以实时显示网卡流量大小:
本文转自birdinroom 51CTO博客,原文链接:http://blog.51cto.com/birdinroom/1344059,如需转载请自行联系原作者