#!/usr/bin/perl -w
#
#NAME
#  ____ -
#
#SYNOPSIS
#  ____ [file]..
#
#DESCRIPTION
#
#OPTIONS
#
#EXAMPLES
#
#FILES
#
#BUGS
#
#SEE ALSO
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #

$| = 1;
($P = $0) =~ s".*/"";	# Our name, minus directories
$V = $ENV{"V_$P"} || 1;	# Verbose/trace/debug level
$exitstat = 0;			# Set to nonzero for failure

#AAL = '/usr/local/apache/logs/access_log';
$AAL = '/var/log/httpd-access.log';

%AAlist = glob("$AAL*");
logfile:
for $log (%AAlist) {
	print "$P: log=\"$log\"\n" if $V>1;
	if ($log =~ /\.gz$/) {	# gzipped log
		if (open(LF,"zcat $log |")) {
			print "$P: Unzipping $log\n" if $V>1;
		} else {
			print STDERR "$P: Can't zcat $log ($!)\n" if $V>0;
			next logfile;
		}
	} else {
		if (open(LF,$log)) {
			print "$P: Reading $log\n" if $V>1;
		} else {
			print STDERR "$P: Can't read $log ($!)\n" if $V>0;
			next logfile;
		}
	}
	while ($line = <LF>) {
		for $pat (@ARGV) {
			if ($line =~ $pat) {
				print $line;
			}
		}
	}
}

exit $exitstat;

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
