Chinaunix首页 | 论坛 | 博客
  • 博客访问: 110716
  • 博文数量: 27
  • 博客积分: 573
  • 博客等级: 中士
  • 技术积分: 265
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-13 12:59
文章分类

全部博文(27)

文章存档

2012年(3)

2011年(24)

分类: LINUX

2011-09-11 12:54:48

  1. #!/bin/bash
  2. if [ -z "$1" ]
  3. then
  4.     echo "Oops...Please specify network device name."
  5.     echo "Usage:    `basename $0` device"
  6.     echo "eg.     `basename $0` eth0"
  7.     exit 1
  8. else
  9.     dev_name="$1"
  10. fi

  11. /sbin/ifconfig $dev_name 2> /dev/null > /dev/null
  12. if [ $? -ne 0 ]
  13. then
  14.     echo "Oops...Cannot find the specified device."
  15.     exit 1
  16. fi

  17. while true
  18. do
  19.     rece_all1=`/sbin/ifconfig $dev_name | grep bytes | awk '{print $2}' | awk -F : '{print $2}'`
  20.     send_all1=`/sbin/ifconfig $dev_name | grep bytes | awk '{print $6}' | awk -F : '{print $2}'`
  21.     sleep 1
  22.     rece_all2=`/sbin/ifconfig $dev_name | grep bytes | awk '{print $2}' | awk -F : '{print $2}'`
  23.     send_all2=`/sbin/ifconfig $dev_name | grep bytes | awk '{print $6}' | awk -F : '{print $2}'`
  24.     rece=`expr $rece_all2 - $rece_all1`
  25.     send=`expr $send_all2 - $send_all1`
  26.     clear
  27.     echo "Last second receive:$(($rece/1024)) KB    Last second Send:$(($send/1024)) KB"
  28.     echo "Total receive:$(($rece_all2/1024)) KB ($(($rece_all2/1024/1024))MB)    Total send:$(($send_all2/1024)) KB ($(($send_all2/1024/1024))MB)"
  29. done
阅读(2050) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~