#!/usr/local/bin/perl # wnhits - summarize hits on wn server. # Assumes common log format. # 21 Sep 95 Paul DuBois, dubois@primate.wisc.edu # get script name for messages ($prog = $0) =~ s|.*/||; # BEGIN SITE-CONFIGURABLE STUFF (change as necessary) # default log file if no arguments given $defaultlog = "/usr/local/log/wnlog"; # requests ending in / have this added to them $defaultpage = "index.html"; # END SITE-CONFIGURABLE STUFF push (@ARGV, $defaultlog) if @ARGV == 0; $summarycmd = "sort | uniq -c | sort -rn"; open (FH, "|$summarycmd") || die "$prog: cannot open summary command\n"; while (<>) { ($host, $rfc931, $authuser, $timestamp, $request, $status, $bytes) = /^(\S+) +(\S+) +(\S+) +\[(.+)\] +\"(.+)\" +(\S+) +(\S+)/; # no longer exclude bytes == - lines; I put that in to exclude aborted # connections, but it also excludes CGI requests that don't send a # byte count in the output stream #next unless $status == 200 && $bytes ne "-"; next unless $status == 200; ($method, $path, $httpvers) = split (' ', $request, 3); # convert some common hex chars to ascii equivalents $path =~ s/%3B/;/g; #$path =~ s/%3F/?/g; # fix paths that have // or /./ in them $path =~ s|//+|/|g; 1 while s|/\./|/|; $path .= $defaultpage if $path =~ /\/$/; # strip trailing query information $path =~ s/;.*//; $path =~ s/\?.*//; print FH "$path\n"; } close (FH); exit (0);