• perl 正则分组 或


    jrhmpt01:/tmp# cat sum.pl 
    open (LOG ,"<","tmp.out");  
                        while (<LOG>) {  
                        chomp; 
    ##10.171.246.184 - - [05/Feb/2016:20:32:50 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 180.120.21.62
    #10.171.246.184 - - [05/Feb/2016:20:46:24 +0800] "GET /web/noauth?method=%2Fnotice%2Fpage&type=1&pageNum=1&pageSize=5&_=1454676377831 HTTP/1.1" 200 1134 0.032 122.234.182.28
    if ($_ =~ /.*s+"(POST|GET)s*(.*?)s*HTTP.*?(d{1,3}.d{1,3}.d{1,3}.d{1,3})$/){
    print "$1 is $1
    ";
    $url=$2;
    print "$url is $url
    ";
    $ip=$3;
    print "$ip is $ip
    ";
    $var=$url.$ip;
    $hash{$var}++;
    }}
    while(my($ip, $times) = each %hash) {
                       print "$ip access count(*) ==   $times
    ";
    };
    jrhmpt01:/tmp# cp tmp.out tmp.out.bak
    jrhmpt01:/tmp# vim tmp.out
    jrhmpt01:/tmp# perl sum.pl 
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is GET
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    /web/sendregistersmscode117.149.104.182 access count(*) ==   10
    jrhmpt01:/tmp# cat tmp.out
    10.252.142.174 - - [06/Feb/2016:08:05:13 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.000 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:13 +0800] "GET /web/sendregistersmscode HTTP/1.1" 200 49 0.000 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:19 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:23 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:24 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:29 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:34 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:35 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:37 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.002 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:51 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    jrhmpt01:/tmp# grep 117.149.104.182  tmp.out
    10.252.142.174 - - [06/Feb/2016:08:05:13 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.000 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:13 +0800] "GET /web/sendregistersmscode HTTP/1.1" 200 49 0.000 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:19 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:23 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:24 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:29 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:34 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:35 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:37 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.002 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:51 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182

  • 相关阅读:
    当前日志损坏解决一例
    Oracle 1204 RAC failover 测试 (一)
    Logical standby跳过个别SQL不Apply的测试
    Data guard 又出问题了
    CPIO无反应
    回答棉花糖先生关于我说的DB自动增加Index的问题
    SSD硬盘,先不要用在Server上
    ORA00304: requested INSTANCE_NUMBER is busy,终于解决
    .Net运行时的相互关系
    CSS布局探密04
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351019.html
Copyright © 2020-2023  润新知