您的位置:首页 > 理论基础 > 计算机网络

linux 网络流量监控脚本

2013-03-07 09:43 501 查看
#!/bin/bash

if [ -z "$1" ]

then

echo "Oops...Please specify network device name."

echo "Usage: `basename $0` device"

echo "eg. `basename $0` eth0"

exit 1

else

dev_name="$1"

fi

/sbin/ifconfig $dev_name 2> /dev/null > /dev/null

if [ $? -ne 0 ]

then

echo "Oops...Cannot find the specified device."

exit 1

fi

while true

do

rece_all1=`/sbin/ifconfig $dev_name | grep bytes | awk '{print $2}' | awk -F : '{print $2}'`

send_all1=`/sbin/ifconfig $dev_name | grep bytes | awk '{print $6}' | awk -F : '{print $2}'`

sleep 1

rece_all2=`/sbin/ifconfig $dev_name | grep bytes | awk '{print $2}' | awk -F : '{print $2}'`

send_all2=`/sbin/ifconfig $dev_name | grep bytes | awk '{print $6}' | awk -F : '{print $2}'`

rece=`expr $rece_all2 - $rece_all1`

send=`expr $send_all2 - $send_all1`

clear

echo "Last second receive:$(($rece/1024)) KB Last second Send:$(($send/1024)) KB"

echo "Total receive:$(($rece_all2/1024)) KB ($(($rece_all2/1024/1024))MB) Total send:$(($send_all2/1024)) KB ($(($send_all2/1024/1024))MB)"

done
http://blog.chinaunix.net/uid-25524253-id-2783110.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 流量监控