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

这篇文章主要为大家分享一个简单的监控流量脚本,需要的朋友可以参考下。

实现代码:

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



原文:http://www.androidstar.cn/一个监控网卡流量的shell脚本/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值