【转】通过shell 脚本查看服务器的时时流量

 

原文地址:http://www.dbasky.net/archives/2012/11/shell-1.html

 

vi network.sh

#!/bin/bash

 
ETH=$1
ETH=${ETH:-eth0}
IP=`ifconfig $ETH|awk -F '[ :]+' '/inet addr/{print $4}'`
 
while true;do
        let I+=1
        NOW=`date +"%F %T"`
        TX1=`ifconfig $ETH|grep bytes|awk -F '[ :]+' '{print $9}'`
        RX1=`ifconfig $ETH|grep bytes|awk -F '[ :]+' '{print $4}'`
        sleep 1
        TX2=`ifconfig $ETH|grep bytes|awk -F '[ :]+' '{print $9}'`
        RX2=`ifconfig $ETH|grep bytes|awk -F '[ :]+' '{print $4}'`
 
        let TX=(TX2-TX1)/1024
        let RX=(RX2-RX1)/1024
        let TX_TOTAL+=$TX
        let RX_TOTAL+=$RX
        let TX_AVERAGE=TX_TOTAL/${I}
        let RX_AVERAGE=RX_TOTAL/${I}
 
        clear
 
        printf "%10s\t%20s\n" "Device $ETH [$IP]" "$NOW"
        echo "============================================================="
        printf "%10s\t%20s\t%20s\n" CURRENT: in:${RX}KB/s out:${TX}KB/s
        printf "%10s\t%20s\t%20s\n" AVERAGE: in:${RX_AVERAGE}KB/s out:${TX_AVERAGE}KB/s
        printf "%10s\t%20s\t%20s\n" TOTAL: in:${RX_TOTAL}KB out:${TX_TOTAL}KB
done

使用方法:

./network.sh eht0

Device eth0 [192.168.1.54]       2012-11-06 17:11:09
=============================================================
  CURRENT:                 in:28KB/s              out:38KB/s
  AVERAGE:                 in:48KB/s              out:72KB/s
    TOTAL:                  in:679KB              out:1020KB

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值