#!/usr/bin/perl -w # simple log parser viewer thingie by Chris Angell - chris@chrisangell.com use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); # change this line to the directory where the logfile reside my $LOGS_DIR = "/home/chrisangell/www/cgi-bin/weblog_hit_viewer/logs"; ############################################################################## # you don't have to change anything past this area - but you may if you wish # ############################################################################## my $q = CGI->new; # make a CGI object my %stats; # key is filename, value is hits my @files; # list of files that were parsed opendir DIR, $LOGS_DIR or die "opendir: $!"; for my $file (grep !/^\./, readdir(DIR)) { push @files, $file; open FH, "$LOGS_DIR/$file" or die "open: $!"; while (local $_ = ) { # 64.71.144.13 - - [24/Sep/2004:03:47:06 -0700] "GET /darth_angelus.htm m/ \S+ # ip or hostname \s+ # blank space - # a dask [^-]+ # not a dash - # another dask \s+ # whitespace [^"]+ # waiting to hit the double quote before GET " # double quote [^\/]+ # GET PUT etc. (\S+) # the filename /x or next; # no match? move on to the next line # increase the count $stats{$1}++; } close FH; } close DIR; print $q->header, $q->start_html("Web Stats"); print "

List of files: @files

\n"; print "\n"; print "\n" for sort { $stats{$b} <=> $stats{$a} } keys %stats; print "
$_$stats{$_}
\n"; print $q->end_html;