[lug] extract, filter, purge logs...

Walter Pienciak walter at frii.com
Thu Sep 27 11:42:08 MDT 2001


And yet another, which sorts the hostnames based on number of hits.
My oldest daughter wanted to know how many people were looking
at her fiction; that line can be eliminated or modified as you wish.
And the 192.168 stuff skips all the hits from within our internal
network.

The log you want to analyze is the single command-line argument.

Walter

!/usr/bin/perl -wT

use strict;
use Socket;

my $l = $ARGV[0];
print "Operating on $l\n";

open LOG, "$l" or die "Can't open it: $!";

my %sites;
while (<LOG>) {
    next if (/192\.168\.168/o);
    chomp;
    my ($ip, $foo) = /^(\S+) (.*)$/;
    next unless ($foo =~ / fiction /);
    $sites{$ip}++;
}

foreach my $ip (sort by_visits keys %sites) {
    my $name = gethostbyaddr(inet_aton($ip), AF_INET)
        or print "$ip: [", $sites{$ip}, "]\n";
    print "$name: [", $sites{$ip}, "]\n" if defined($name);
}

sub by_visits { $sites{$b} <=> $sites{$a} }

#  Th-th-that's all, folks!




More information about the LUG mailing list