当前位置: 移动技术网 > 网络运营>服务器>Linux > Shell脚本查看网卡实时流量

Shell脚本查看网卡实时流量

2017年12月12日  | 移动技术网网络运营  | 我要评论

复制代码 代码如下:

#!/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

调用方式:

复制代码 代码如下:

./traff.sh eth1

bash traff.sh eth1

可以实时显示网卡流量大小:

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网