#!/local/bin/perl
#
# Userlogextractor
#
# Extracts last months stats from the userlog for mailing to the maintainer
# of the regional domain stats.
#
# Copyright Ove Ruben R Olsen 1993.
#
# Dedicated Johanne Revheim with love and pleasure
#
# We use this crontab entry: 59 7 1 * * /local/irc/logexc
#
# Version 1.00-002 Sun Jan 22 02:27:49 GMT 1995 
#
################################################################################
#
# Config section

$EMAIL   	= "user@host.domain"; 	# Who to mail
$logfile  	= "/local/irc/userlog"; # Where the userlog lives
$MAIL 		= 1 ; 			# Uncomment if you wanna mail directly. 
					# Else the stuff will go to stdout.

# End of config section. No need to go beyond this line.
#
################################################################################
################################################################################
require 'ctime.pl' ; 

chop ($host = `hostname`); 
$Mnd = (localtime())[4]; 
$Mnd = 12 if ($Mnd == 0); $Mnd = "0$Mnd" if ($Mnd < 10 ); 
$SMnd = @ctime'MoY[$Mnd-1] ; 
($Year) = (&ctime(time) =~ /19(\d\d)$/); 
$Year -- if ($Mnd == 12) ;
&Mailer if ($MAIL); 

open (FIL,"$logfile") || die "userlog: $!\n"; 
while (<FIL>) { print if /^\w+\s+$SMnd/ ; } 
close (MAIL) ; 

sub Mailer { 
  open (MAIL,"|mail -s 'USERLOG: $host $Year.$Mnd' $EMAIL") || 
    die "Mailer $!\n"; 
  select (MAIL); $| = 1 ; 
}

