#!/usr/bin/perl -w
##########################################################################
# $Id: onlyservice,v 1.3 2002/03/28 05:00:04 kirk Exp $
##########################################################################
# $Log: onlyservice,v $
# Revision 1.3  2002/03/28 05:00:04  kirk
# - Implemented several bug fixes and patches that have been sent in
# - Fixed a possible root exploit using a race condition in /tmp
# - Fixed bugs 46371, 56191, 58578, 61202, 61829, 61831, 61832 from bugzilla.redhat.com
#
# Revision 1.2  1998/02/23 01:17:03  kirk
# Getting ready for a first distribution
#
# Revision 1.1  1998/02/22 23:28:28  kirk
# Commented and rearranged some things
#
##########################################################################

########################################################
# This was written and is maintained by:
#    Kirk Bauer <kirk@kaybee.org>
#
# Please send all comments, suggestions, bug reports,
#    etc, to kirk@kaybee.org.
#
########################################################

# This will pick out only the wanted service from a logfile
# in the standard /var/log/messages format.  Case insensitive.

$ServiceName = $ARGV[0];
if ( $ENV{'LOGWATCH_DEBUG'} > 5 ) {
   print STDERR "DEBUG: Inside OnlyService for $ServiceName\n";
}

while (defined($ThisLine = <STDIN>)) {
    if ($ThisLine =~ m/^... .. ..:..:.. [^ ]* $ServiceName\[[0123456789]*\]: /io) {
      print $ThisLine;
    }
    elsif ($ThisLine =~ m/^... .. ..:..:.. [^ ]* $ServiceName: /io) {
      print $ThisLine;
    }
}
