# Access log slicer by A.L. Mudd (perl@tonymudd.co.uk) print "\nAccess log slicer.\n------------------\n"; # open the old refer.txt file and read it in. open (REFS,"refer.txt") or print "Could not open refer.txt\n"; while ($line = ) { chomp $line; $refs{$line} = 1; } close REFS; # open the old view.txt. open (VIEW,"view.txt") or print "Could not open view.txt\n"; while ($line = ) { chomp $line; $views{$line} = 1; } close VIEW; open (INFILE, "access.log") or die "Could not open file $!\n"; while ($line = ) { # s08103.vdo.com.au - - [16/Feb/1998:10:05:08 +0000] home.clara.net "GET /alm/antigrav.html HTTP/1.0" 200 2086 "http://home.clara.net/alm/" "Mozilla/4.0 (compatible; MSIE 4.0; Windows 95)" if ($line=~ /^([\w\d\.-]+)\s-\s-\s\[(.+)\s.+\]\s(.+)\s\"\w+\s(.+)\sHTTP\/.+\"\s\d+\s[\d-]+\s\"(.+)\"\s\".+\"\n$/) { $remote_host = $1; $time = $2; # $3 is local hostname $localhost = $3; $request = $4; $referrer = $5; if ( ($localhost =~ /^home\.clara\.net$/) || ($localhost =~ /^-$/ )) { # that was the hostname used in the request, so remove the # first part of the request - it's the hostname $request =~ /^\/[^\/]+(.+)$/; $request = $1; } print "$request\t$referrer\n"; $refs{$referrer} = 1; $views{$remote_host} = 1; } else { print "line didn't match $line"; } } close INFILE; # now write out the new refs file. open (REFS, ">refer.txt") or die "Could not open refer.txt $!\n"; foreach $ref (sort keys %refs) { print REFS "$ref\n"; } close REFS; # now write out the new view file. open (VIEW, ">view.txt") or die "Could not open view.txt $!\n"; foreach $view (sort keys %views) { print VIEW "$view\n"; } close VIEW;