网络流量监控脚本
2015-09-21 10:07
579 查看
#!/bin/bash ROOT_UID=0 E_NOTROOT=67 i=0 if [ "$UID" -ne "$ROOT_UID" ]; then echo "Must be root to run this script." exit $E_NOTROOT fi if [ -n "$1" ]; then eth_name=$1 else eth_name="eth0" fi send_o=`ifconfig $eth_name | grep bytes | awk '{print $6}' | awk -F : '{print $2}'` recv_o=`ifconfig $eth_name | grep bytes | awk '{print $2}' | awk -F : '{print $2}'` send_n=$send_o recv_n=$recv_o while [ $i -le 100000 ]; do send_l=$send_n recv_l=$recv_n sleep 1 send_n=`ifconfig $eth_name | grep bytes | awk '{print $6}' | awk -F : '{print $2}'` recv_n=`ifconfig $eth_name | grep bytes | awk '{print $2}' | awk -F : '{print $2}'` i=`expr $i + 1` send_r=`expr $send_n - $send_l` recv_r=`expr $recv_n - $recv_l` total_r=`expr $send_r + $recv_r` send_ra=`expr '(' $send_n - $send_o ')' / $i` recv_ra=`expr '(' $recv_n - $recv_o ')' / $i` total_ra=`expr $send_ra + $recv_ra` sendn=`ifconfig $eth_name | grep bytes | awk -F '(' '{print $3}' | awk -F ')' '{print $1}'` recvn=`ifconfig $eth_name | grep bytes | awk -F '(' '{print $2}' | awk -F ')' '{print $1}'` clear echo "Last second : Send rate: $send_r Bytes/sec Recv rate: $recv_r Bytes/sec Total rate: $total_r Bytes/sec" echo "Average value: Send rate: $send_ra Bytes/sec Recv rate: $recv_ra Bytes/sec Total rate: $total_ra Bytes/sec" echo "Total traffic after startup: Send traffic: $sendn Recv traffic: $recvn" done exit 0
先前网上找来的有些错误,自己修改了下.在redhat6和centos6测试没问题
相关文章推荐
- android wifi 无线调试
- 运维入门
- 动态清空 nohup 输出文件
- install scrapy with pip and easy_install
- Linux Shell常用技巧
- shell字符串操作详解
- Shell中删除某些文件外所有文件的3个方法
- Ruby中执行Linux shell命令的六种方法详解
- VB使用shell函数打开外部exe程序的实现方法
- Shell编程的一些知识集合
- Shell中的for和while循环详细总结
- 什么是Shell?Shell脚本基础知识详细介绍
- Shell脚本中引用、调用另一个脚本文件的2种方法
- Shell脚本解压rpm软件包
- Shell脚本实现复制文件到多台服务器的代码分享
- Shell脚本实现批量替换文件内容
- Shell脚本实现的一个简易Web服务器例子分享
- linux Shell学习笔记第五天
- Perl 获取shell命令的执行结果
- Shell脚本中非交互式修改密码的两种方法