分享

监控网卡流量脚本...

 milo2008 2010-10-19
监控网卡流量脚本
  前言:这个脚本是用来监控网卡的瞬时流量的,跟Cacti的计算结果完全吻合。如果想让系统每多少分钟取一次可以将此脚本改良成任务计划执行的脚本并记录到日志中。
   
 
   
#!/bin/bash
############################
##
##  Author : Ajian
##  Time : 2007-9-21
##  File:  netflood.sh
##  watch the eth0 or eth1
#################################
#Set the varible.
ETH=eth0
while : ; do
        time=`date +%m"-"%d" "%k":"%M`
        day=`date +%m"-"%d`
        rx_before=`ifconfig $ETH|sed -n "8"p|awk '{print $2}'|cut -c7-`
        tx_before=`ifconfig $ETH|sed -n "8"p|awk '{print $6}'|cut -c7-`
        sleep 2
        rx_after=`ifconfig $ETH|sed -n "8"p|awk '{print $2}'|cut -c7-`
        tx_after=`ifconfig $ETH|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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多