手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >Shell脚本查看网卡实时流量
Shell脚本查看网卡实时流量
摘要:复制代码代码如下:#!/bin/bashwhile["1"]doeth=$1RXpre=$(cat/proc/net/dev|grep$et...

复制代码 代码如下:

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

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

Shell脚本查看网卡实时流量1

【Shell脚本查看网卡实时流量】相关文章:

Shell脚本实现的单机流量统计功能

shell脚本中echo显示内容带颜色的实现方法

Shell脚本批量重命名文件后缀的3种实现

Shell脚本处理浮点数的运算和比较实例

Shell脚本数组用法小结

Shell脚本函数定义和函数参数

对Shell 脚本加密的方法

Shell脚本实现自动修改IP地址

5个Shell脚本编程入门练习例子

Shell脚本实现温和方式重启Centos系统

精品推荐
分类导航