当前位置: 移动技术网 > 网络运营>服务器>Linux > 一个监控网卡流量的shell脚本

一个监控网卡流量的shell脚本

2017年12月12日  | 移动技术网网络运营  | 我要评论
实现代码: #!/bin/bash eth_in_old=$(ifconfig eth0|grep "rx bytes"|sed 's/rx bytes:/

实现代码:

#!/bin/bash

eth_in_old=$(ifconfig eth0|grep "rx bytes"|sed 's/rx bytes://'|awk '{print $1}')
eth_out_old=$(ifconfig eth0|grep "rx bytes"|sed 's/.*tx bytes://'|awk '{print $1}')

sleep 1

eth_in_new=$(ifconfig eth0|grep "rx bytes"|sed 's/rx bytes://'|awk '{print $1}')
eth_out_new=$(ifconfig eth0|grep "rx bytes"|sed 's/.*tx bytes://'|awk '{print $1}')
eth_in=$(echo "scale=2;($eth_in_new - $eth_in_old)/1000.0"|bc)
eth_out=$(echo "scale=2;($eth_out_new - $eth_out_old)/1000" | bc)
echo "in: $eth_in kb"
echo "out:$eth_out kb"

输出:
[root@localhost hbshell]# ./traffic.sh

in: 1.74 kb
out:1.17 kb

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网