Chinaunix首页 | 论坛 | 博客
  • 博客访问: 49548
  • 博文数量: 51
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 72
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-22 16:36
个人简介

地方

文章分类

全部博文(51)

文章存档

2013年(51)

我的朋友

分类: LINUX

2013-04-22 16:43:38

#!/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的监控流量查不多,如果想暂时统计当前网络的流量,比较实用!

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