zoukankan      html  css  js  c++  java
  • 挑出IIS日志里某一文件的请求次数

    要统计广告的弹出次数,找不到这种IIS日志分析器,只好写了个脚本。

    =pod
       说明
       把iis日志传到LINUX,再挑出日志里出现关键字的行,如cat ex*.log |grep divMove.js>>iis.log
       再生成excel文件,如xxx.pl iis.log>>iis.csv
    =cut
     
       #!/usr/bin/perl -w
       use strict;
       my $file;
       my $eachline;
       my %hash;
       my @arr_file=@ARGV;
      foreach $file(@arr_file){
        
        open(IIS_LOG,$file)||die"err: $! \n";
        while (defined ($eachline =<IIS_LOG>)) {
            
           #正则
           #2010-05-20 00:03:15 W3SVC1 218.5.79.57 GET /divMove.js - 80 - 221.178.26.163 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1)+) 218.5.79.57 200 0 64 0 394
            if($eachline=~/^2010-\d+-\d+\s.+ W3SVC\d*\s+218\.5\.79\.57\s+GET\s+\/divMove.js\s+-\s+80\s+-\s+(?<getip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+.+\d$/){
             #print "$+{getip}\n";   
                #以IP做哈希表的key,累加出现次数
              if(exists $hash{$+{getip}}){
                $hash{$+{getip}}=$hash{$+{getip}}+1
              }
              else{         
                $hash{$+{getip}}=1 
              }
              
            }
     
        }
        
      }
         my $key;
         my $value;
         while (($key, $value) = each %hash){
            print "$key,$value\n";
            }
    
    


    以上脚本生成以下表格

    202.100.121.46 1209
    123.180.14.253 185
    222.90.15.209 179
  • 相关阅读:
    Sprint2-3.0
    6/13 Sprint2 看板和燃尽图
    6/8/9/10/11 Sprint2 看板和燃尽图
    相互观看与评价
    复利计算器结对2.0
    汉堡包1.0
    复利计算5.0 结对
    《构建之法》第四章 二人合作 读后感
    复利计算器单元测试测试报告
    实验一、命令解释程序的编写实验
  • 原文地址:https://www.cnblogs.com/LCX/p/1743603.html
Copyright © 2011-2022 走看看