Simple PERL script to summarize the User-Agent log

From: John Heaton <john@dont-contact.us>
Date: Fri, 6 Dec 1996 13:09:35 +0000 (GMT)

Greetings,

Below is a very simple script that I threw together to produce a summary of
the useragent log on the newer versions of squid 1.1beta.

-----------------------------------------------------------------------

#!/usr/bin/perl
#
# John@MCC.ac.uk
# John@Pharmweb.NET

require "getopts.pl";
&Getopts('FML:');

open (ACCESS, "/opt/Squid/logs/useragent.0");

while (<ACCESS>) {
        ($host, $timestamp, $agent) =
        /^(\S+) \[(.+)\] \"(.+)\"\s/;
        if ($agent ne '-') {
                if ($opt_M) {
                         $agent =~ tr/\// /;
                        $agent =~ tr/\(/ /;
                }
                if ($opt_F) {
                        next unless $seen{$agent}++;
                } else {
                        @inline=split(/ /, $agent);
                        next unless $seen{$inline[0]}++;
                }
        }
}

$total=0;
if (!$opt_L) {$opt_L=0}

print "Summary of User-Agent Strings\n(greater than $opt_L percent)\n\n";

foreach $browser (keys(%seen)) {
        $total=$total+$seen{$browser};
}

foreach $browser (sort keys(%seen)) {
        $percent=$seen{$browser}/$total*100;
        if ($percent >= $opt_L) { write; }
}

print "\n\nTotal entries in log = $total\n";

format STDOUT =
@>>>>>>> :@##.####% : @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$seen{$browser}, $percent, $browser
.

-----------------------------------------------------------------------

Sample output with '-L1' option

-----------------------------------------------------------------------
 Summary of User-Agent Strings
 (greater than 1 percent)
 
      783 : 1.6102% : Mozilla/1.1N
     3379 : 6.9485% : Mozilla/1.22
     1352 : 2.7802% : Mozilla/1.2N
     3308 : 6.8025% : Mozilla/2.0
     1292 : 2.6569% : Mozilla/2.01
     2042 : 4.1991% : Mozilla/2.02
    28740 : 59.1005% : Mozilla/3.0
     4103 : 8.4374% : Mozilla/3.01
     1297 : 2.6671% : Mozilla/3.01Gold
     1668 : 3.4301% : Mozilla/3.0Gold
 
 Total entries in log = 48629
-----------------------------------------------------------------------

John

-- 
  John Heaton                       Phone: (+44 161)/(0161) 275-6011
  Manchester Computing                FAX: (+44 161)/(0161) 275-6040
  The University of Manchester
  Oxford Road, Manchester           Email: John@PharmWeb.net
  M13-9PL, UK                         WWW: http://www.mcc.ac.uk/John/
Received on Fri Dec 06 1996 - 05:20:15 MST

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:33:50 MST