#!/usr/bin/perl -w #------------------------------------------- # log_check.pl - poor man's log analysis # Copyright (C) 1999 Jonathan Anthony Field (jon@binadopta.com) # # Full documentation is available via perldoc # # This program may be used, modified, and distributed under # the same terms as Perl itself. I request that the original # copyright notice remain intact and that any modifications # are noted here. #------------------------------------------- use strict; open FILE, shift(@ARGV) or die $!; my (%users, %urls); $| = 1; # go through each line of the file while (my $line = ) { # split off just the parts of the line we need my ($user, $date, $url) = (split /\s+/, $line)[0,3,6]; # if it's the first line, print out the heading if ($. == 1) { $date =~ s/^\[//; print "-" x 43 . "\n"; print "Covering $date to present\n"; print "-" x 43 . "\n"; print "Lines\t\tUnique IPs\tUnique URLs\n"; print "-" x 43 . "\n"; } $url =~ s/\?.*//; # skips images if ($url !~ /\.gif/i and $url !~ /\.jpg/i) { # count the user by IP address ++$users{$user}; # count hits to the url ++$urls{$url}; } # keep a running status so the script doesn't appear to hang print( $. . "\t\t" . scalar(keys(%users)) . "\t\t" . scalar(keys(%urls)) . "\r" ) if not $. % 500; } print( $. . "\t\t" . scalar(keys(%users)) . "\t\t" . scalar(keys(%urls)) . "\r" ); print "\n"; print "-" x 43 . "\n"; # tally the average my $total; foreach (keys %users) { $total += $users{$_}; } print "Average Pages per IP: ", $total / scalar(keys(%users)), "\n"; print "-" x 43 . "\n"; print "10 Most Popular pages:\n"; # display the ten most visited my @popular = sort { $urls{$b} <=> $urls{$a} } keys %urls; foreach (0..9) { print "$urls{$popular[$_]}\tviews for $popular[$_]\n"; } print "-" x 43 . "\n"; close FILE; print "\n"; exit; =head1 NAME log_check.pl - poor man's log analysis =head1 DESCRIPTION Tallies logs - provides unique IPs, unique URLs, URLs per IP, and top ten (unique visits only). Excludes images, and combines query strings. =head1 USAGE perl log_check.pl logfile.log =head1 BUGS It only works if the log file is in the default Apache log format. =head1 AUTHOR Copyright (C) 1999 Jonathan Anthony Field (jon@binadopta.com) =head1 LICENSE This program may be used, modified, and distributed under the same terms as Perl itself. I request that the original copyright notice remain intact and any modifications are noted here.