Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2114847
  • 博文数量: 227
  • 博客积分: 10521
  • 博客等级: 上将
  • 技术积分: 3452
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-20 14:59
个人简介

低调做人,高调做事!

文章分类

全部博文(227)

文章存档

2013年(4)

2012年(8)

2011年(16)

2010年(24)

2009年(92)

2008年(83)

分类: LINUX

2008-11-29 22:08:44

#!/bin/bash

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



执行结果:
[root@localhost ~]# ./test.sh
11-29 22:06 Now_In_Speed: 7173kbps Now_OUt_Speed: 26691kbps
11-29 22:06 Now_In_Speed: 6228kbps Now_OUt_Speed: 30047kbps
11-29 22:06 Now_In_Speed: 2310kbps Now_OUt_Speed: 34677kbps
11-29 22:06 Now_In_Speed: 3092kbps Now_OUt_Speed: 36550kbps
11-29 22:06 Now_In_Speed: 8447kbps Now_OUt_Speed: 33395kbps
11-29 22:06 Now_In_Speed: 6733kbps Now_OUt_Speed: 31551kbps
11-29 22:06 Now_In_Speed: 2290kbps Now_OUt_Speed: 23405kbps
11-29 22:06 Now_In_Speed: 2199kbps Now_OUt_Speed: 32412kbps
11-29 22:06 Now_In_Speed: 2177kbps Now_OUt_Speed: 43927kbps
11-29 22:06 Now_In_Speed: 2969kbps Now_OUt_Speed: 40057kbps
11-29 22:06 Now_In_Speed: 2062kbps Now_OUt_Speed: 32435kbps
11-29 22:06 Now_In_Speed: 1557kbps Now_OUt_Speed: 27812kbps


说明:结果还是比较准确的,和cacti的监控流量查不多,如果想暂时统计当前网络的流量,比较实用!

阅读(2935) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~