#!/usr/bin/perl # # generate referrer statistics from $logfile. output to stdout. # # (c) 1998 James Abendschan, JAMMED Systems # # 8 May 1998 - Initial code # # # my $logfile is in this format -- you may need to modify the $refer =~ s/.. # line to suit your setup # # 1.2.3.4 - - [07/May/1998:23:59:35 -0700] "GET /newzbot-cgi-bin/readnews.pl HTTP/1.0" 200 417 |- -> /newzbot-cgi-bin/readnews.pl|Mozilla/2.0 (compatible; MSIE 3.02; Update a; Winblows 95)|www.jammed.com # # $logfile= "/jsi/common/archives/www/logs/access_log"; # # exclude lines matching this pattern. To exclude multiple items, # you might do something like $exclude="www.siteone.com|/cgi-bin/|sitetwo.com"; # $exclude = "www.jammed.com|file:\\|file:\/" . $ARGV[0]; # # show these top sites # $top = 100; # # header & trailer # $hostname = `hostname`; $update = `date`; $header=" Sites that refer to www.jammed.com

Sites that refer to www.jammed.com

Last automatic update: $update on $hostname.

The following is a list of the most popular referring links to www.jammed.com. Excluded from this list are bookmarks (file:// URLs) and referring links from jammed.com.


"; $trailer="
Return to JAMMED.COM

Download the program that generated this page "; # # do it # open (LOG, $logfile) || die "can't open $logfile: $!"; LINE: while ($line = ) { $url = "http://www.jammed.com" . (split(" ", $line))[6]; $refer = (split(" ", $line))[10]; $refer =~ s/\|//g; $line =~ tr/%7E/~/; $line =~ tr/%7e/~/; next LINE if ($line !~ / 200 /); # only show valid requests next LINE if ($refer =~ /^-/); next LINE if ($refer =~ /${exclude}/i); $key = "$url

From: $refer"; $hash{$key} = $hash{$key} + 1; } print $header; foreach (sort {$hash{$b} <=> $hash{$a}} (keys %hash)) { $n++; print "$n. $hash{$_} hits to \t $_\n
"; goto BAIL if ($n == $top); } BAIL: print $trailer; exit 0;