Perl解析APACHE日志
10.1.1.95 - e800 [18/Mar/2005:12:21:42 +0800] "GET /stats...
扫描右侧二维码阅读全文
05
2009/06

Perl解析APACHE日志

10.1.1.95 - e800 [18/Mar/2005:12:21:42 +0800] "GET /stats/awstats.pl?config=e800 HTTP/1.1" 200 899 "http://10.1.1.1/pv/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Maxthon)"

以上是APACHE日志的格式,有时候我们直接使用Perl来分析日志文件并且获取所需要的内容则更加高效

#!perl -w open(FILE,") { m/([0-9.]+?) [\w-]+? [\w-]+? \[(.*?)\] "(.*?)" (\d+?) (\d+?) "(.*?)" "(.*?)"/; $IP{$1}++; $TIME{$2}++; $REQUEST{$3}++; $CODE{$4}++; $BYTES{$5}++; $REFER{$6}++; $CLIENT{$7}++; } print keys %IP; print keys %TIME; print keys %REQUEST; print keys %CODE; print keys %BYTES; print keys %REFER; print keys %CLIENT;

Last modification:November 26th, 2018 at 04:16 pm
If you think my article is useful to you, please feel free to appreciate

5 comments

  1. Johnny Woo

    open(FILE,"

  2. helenajim

    Earlier I thought differently, thanks for the help in this question.

  3. 阳光

    没用过这个哦!不过先学学来放者

  4. liuwei

    Use of uninitialized value in hash element at outlog.pl line 6, line 1.
    Use of uninitialized value in hash element at outlog.pl line 7, line 1.
    Use of uninitialized value in hash element at outlog.pl line 8, line 1.
    Use of uninitialized value in hash element at outlog.pl line 9, line 1.
    Use of uninitialized value in hash element at outlog.pl line 10, line 1.
    Use of uninitialized value in hash element at outlog.pl line 11, line 1.
    Use of uninitialized value in hash element at outlog.pl line 12, line 1.

  5. JamesD

    Thanks for the useful info. It's so interesting

Leave a Comment