#!/usr/bin/perl -w # Created by Ben Okopnik on Tue Dec 13 16:19:37 CST 2005 # Demonstrates log parsing and display - basic die "Usage: ", $0 =~ /([^\/]+)$/, " \n" unless @ARGV; # Apache's Combined Log Format (Common Log Format plus 'referer' and 'UA'): # IP|identd|user|[dy/mon/year:hh:mm:ss zone]|"request"|status|size|"referer"|"UA_string" # @fields = qw/ip ident user date request status size referer ua/; # 0: 80.237.184.66 # 1: - # 2: - # 3: [13/Jan/2007:11:38:05 -0800] # 4: GET /authors/youngman.html HTTP/1.0 # 5: 200 # 6: 3979 # 7: - # 8: WWWeasel Robot v1.00 (http://wwweasel.de) while ( <> ){ @line = /^(\S+) (\S+) (\S+) (\[[^\]]+\]) "([^"]+)" (\d+) (\d+) "([^"]+)" "([^"]+)"/; next unless $line[ 5 ] && $line[ 5 ] == 200; if ( $line[ 4 ] =~ / (.*html) / ){ $files{substr $line[3], 1, 11}{$1}++; } } for $date ( sort keys %files ){ print "$date:\n"; for (sort { $files{$date}{$b} <=> $files{$date}{$a} } keys %{$files{$date}}){ print "\t$_: $files{$date}{$_}\n" if $files{$date}{$_} >= 10; } }