检测网卡流量的shell脚本
发布时间:2014-10-20 编辑:jiaochengji.com
本文介绍下,用shell实现的检测网卡流量的脚本,简单实用,供初学的朋友参考。
在日常的系统管理中,轻便型的shell脚本,往往可以帮上大忙。
下面这个就是,用于检测网卡流量的脚本。
代码如下:
复制代码 代码示例:
#!/bin/bash
#edit by www.jiaochengji.com
NIC=eth1
while : ; do
time=`date +%m"-"%d" "%k":"%M`
day=`date +%m"-"%d`
rx_before=`ifconfig $NIC|sed -n "8"p|awk '{print $2}'|cut -c7-`
tx_before=`ifconfig $NIC|sed -n "8"p|awk '{print $6}'|cut -c7-`
sleep 2
rx_after=`ifconfig $NIC|sed -n "8"p|awk '{print $2}'|cut -c7-`
tx_after=`ifconfig $NIC|sed -n "8"p|awk '{print $6}'|cut -c7-`
rx_result=$[(rx_after-rx_before)/256]
tx_result=$[(tx_after-tx_before)/256]
echo "$time Now_In_Speed: "$rx_result"kbps Now_OUt_Speed: "$tx_result"kbps"
sleep 2
done
调用方法:#edit by www.jiaochengji.com
NIC=eth1
while : ; do
time=`date +%m"-"%d" "%k":"%M`
day=`date +%m"-"%d`
rx_before=`ifconfig $NIC|sed -n "8"p|awk '{print $2}'|cut -c7-`
tx_before=`ifconfig $NIC|sed -n "8"p|awk '{print $6}'|cut -c7-`
sleep 2
rx_after=`ifconfig $NIC|sed -n "8"p|awk '{print $2}'|cut -c7-`
tx_after=`ifconfig $NIC|sed -n "8"p|awk '{print $6}'|cut -c7-`
rx_result=$[(rx_after-rx_before)/256]
tx_result=$[(tx_after-tx_before)/256]
echo "$time Now_In_Speed: "$rx_result"kbps Now_OUt_Speed: "$tx_result"kbps"
sleep 2
done
假设以上脚本文件名为 check_interface.sh,加上可执行权限:
复制代码 代码示例:
#chmod +x check_interface.sh
然后运行命令:复制代码 代码示例:
#./check_interface.sh
即可监测网卡的流量情况。您可能感兴趣的文章:
检测网卡流量的shell脚本
一个测试网卡流量的shell脚本
监控网卡流量的shell脚本分享
计算网卡流量的shell脚本(代码分享)
监测内存使用量、剩余量及网卡流量的shell脚本
linux shell 监控网卡流量的脚本(入门参考)
统计网卡流量的二个shell脚本(ifconfig)(图文)
实时查看Linux网卡流量的shell脚本分享(图文)
shell脚本计算Linux网卡流量
一个自动检测eth0网卡带宽脚本
[关闭]