Great Circle Associates Majordomo-Users
(April 1994)
 

Indexed By Date: [Previous] [Next] Indexed By Thread: [Previous] [Next]

Subject: Re: Log processing
From: pdc @ lunch . asd . sgi . com (Paul Close)
Date: Thu, 21 Apr 1994 18:23:22 -0700 (PDT)
To: Blake_Meike @ terc . edu (Blake Meike)
Cc: majordomo-users @ GreatCircle . COM
In-reply-to: <n1445159937.3082@qm.terc.edu> from "Blake Meike" at Apr 21, 94 05:53:51 pm

>                                                             21/4/94  5:45 PM
> Has anyone out there got any stuff for log post-processing?  Who is using
> what lists, that kind of thing.  Love to hear about it.

Funny you should ask!  I was just packaging my first crack at one for
inclusion in 1.90 (I hope).  Here it is....  Comments/suggestions welcome!

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then feed it
# into a shell via "sh file" or similar.  To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# If this archive is complete, you will see the following message at the end:
#		"End of shell archive."
# Contents:  logsummary.pl
# Wrapped by pdc@lunch on Thu Apr 21 18:22:31 1994
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'logsummary.pl' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'logsummary.pl'\"
else
echo shar: Extracting \"'logsummary.pl'\" \(3190 characters\)
sed "s/^X//" >'logsummary.pl' <<'END_OF_FILE'
X#!/usr/bin/perl
X#
X# Print various statistics about the Log file
X#
X# Todo: summarize admin commands
X#
X# Paul Close, April 1994
X#
X
Xwhile (<>) {
X    if (($mon,$day,$time,$who,$cmd) =
X	/([A-Za-z]+) (\d+) ([\d:]+)\s+.*majordomo\[\d+\]\s+{(.*)} (.*)/)
X    {
X	@f = split(' ',$cmd);
X	$cmd = $f[0];
X	$count{$cmd}++;
X
X	# help
X	# lists
X	# which [address]
X	# approve PASSWD ...
X	if ($cmd eq "approve" ||
X	    $cmd eq "help" ||
X	    $cmd eq "lists" ||
X	    $cmd eq "which")
X	{
X	    eval "\$$cmd++";
X	}
X
X	# index list
X	# info list
X	# who list
X	elsif ($cmd eq "index" ||
X	       $cmd eq "info" ||
X	       $cmd eq "who")
X	{
X	    if ($#f == 1) {
X		$lists{$f[1]}++;
X		$f[1] =~ s/-//g;
X		eval "\$$f[1]{\$cmd}++";
X	    } else {
X		$bad{$cmd}++;
X	    }
X	}
X
X	# get list file
X	# newinfo list passwd
X	elsif ($cmd eq "get" ||
X	       $cmd eq "newinfo")
X	{
X	    if ($#f == 2) {
X		$lists{$f[1]}++;
X		$f[1] =~ s/-//g;
X		eval "\$$f[1]{\$cmd}++";
X		if ($cmd eq "get") {
X		    $req = &ParseAddrs($who);
X		    $long{$req} = $who;
X		    $getcount{$req}++;
X		}
X	    } else {
X		$bad{$cmd}++;
X	    }
X	}
X
X	# subscribe list [address]
X	# unsubscribe list [address]
X	elsif ($cmd eq "subscribe" ||
X	       $cmd eq "unsubscribe")
X	{
X	    if ($#f >= 1) {
X		$lists{$f[1]}++;
X		$f[1] =~ s/-//g;
X		eval "\$$f[1]{\$cmd}++";
X	    } else {
X		$bad{$cmd}++;
X	    }
X	}
X
X	# request cmd list subscribe (for approval)
X	elsif ($cmd eq "request") {
X	    if ($#f >= 2) {
X		$lists{$f[2]}++;
X		$f[2] =~ s/-//g;
X		eval "\$$f[2]{\$cmd}++";
X	    } else {
X		$bad{$cmd}++;
X	    }
X	}
X
X	else {
X	    $unrecognized{$cmd}++;
X	}
X    } else {
X	warn "line $. didn't match!\n";
X    }
X}
X
X#print "Command summary:\n";
X#foreach $cmd (sort keys %count) {
X#    printf "    %-20s %4d\n", $cmd, $count{$cmd};
X#}
X
Xprint "Global commands:\n";
Xprintf("    %-15s %4d\n", "help", $help) if defined($help);
Xprintf("    %-15s %4d\n", "lists", $lists) if defined($lists);
Xprintf("    %-15s %4d\n", "which", $which) if defined($which);
Xprint "\n";
X
X#print "Unrecognized commands:\n";
X#foreach $cmd (sort keys %unrecognized) {
X#    printf "    %-15s %4d\n", $cmd, $unrecognized{$cmd};
X#}
X#print "\n";
X
Xif (defined(%bad)) {
X    print "Incomplete commands:\n";
X    foreach $cmd (sort keys %bad) {
X	printf "    %-15s %4d\n", $cmd, $bad{$cmd};
X    }
X    print "\n";
X}
X
X# skip request and newinfo
Xprint "List               subscr  unsub  index    get   info    who\n";
Xforeach $list (sort keys %lists) {
X    printf "%-18s", substr($list,0,20);
X    $list =~ s/-//g;
X    eval "\%l = \%$list";
X    printf " %6s %6s %6s %6s %6s %6s\n", $l{"subscribe"}, $l{"unsubscribe"},
X       $l{"index"}, $l{"get"}, $l{"info"}, $l{"who"};
X}
Xprint "\n";
X
X@reqs = sort {$getcount{$b}<=>$getcount{$a}} keys %getcount;
Xif ($#reqs >= 0) {
X    print "Top requestors (get command):\n";
X    for ($i=0; $i < 5; $i++) {
X	printf "    %5d  %s\n", $getcount{$reqs[$i]}, $long{$reqs[$i]};
X	last if ($i == $#reqs);
X    }
X}
X
X# from majordomo.pl, modified to work on a single address
X# $addrs = &ParseAddrs($addr_list)
Xsub ParseAddrs {
X    local($_) = shift;
X    1 while s/\([^\(\)]*\)//g; 		# strip comments
X    1 while s/"[^"]*"//g;		# strip comments
X    1 while s/.*<(.*)>.*/\1/;
X    s/^\s+//;
X    s/\s+$//;
X    $_;
X}

END_OF_FILE
echo shar: NEWLINE appended to \"'logsummary.pl'\"
if test 3191 -ne `wc -c <'logsummary.pl'`; then
    echo shar: \"'logsummary.pl'\" unpacked with wrong size!
fi
chmod +x 'logsummary.pl'
# end of 'logsummary.pl'
fi
echo shar: End of shell archive.
exit 0
-- 
Paul Close	     pdc@sgi.com	   ...!{ames, decwrl, uunet}!sgi!pdc

			No fate but what we make




Follow-Ups:
References:
Indexed By Date Previous: Log processing
From: "Blake Meike" <Blake_Meike@terc.edu>
Next: Re: Log processing
From: "Amy K. Kreiling" <kreiling@cs.unc.edu>
Indexed By Thread Previous: Log processing
From: "Blake Meike" <Blake_Meike@terc.edu>
Next: Re: Log processing
From: "Amy K. Kreiling" <kreiling@cs.unc.edu>

Google
 
Search Internet Search www.greatcircle.com