#!/usr/bin/perl -w
##########################################################################
# $Id: applystddate,v 1.6 1998/02/24 01:38:51 kirk Exp $
##########################################################################
# $Log: applystddate,v $
# Revision 1.6  1998/02/24 01:38:51  kirk
# Calls /bin/date explicitly, and not just 'date'...
#
# Revision 1.5  1998/02/23 01:17:02  kirk
# Getting ready for a first distribution
#
# Revision 1.4  1998/02/22 23:28:24  kirk
# Commented and rearranged some things
#
# Revision 1.3  1998/02/14 05:09:23  kirk
# Few minor changes.
#
# Revision 1.2  1998/02/12 18:59:11  kirk
# Added support for log entries w/ no process ID...
#
# Revision 1.1  1998/01/25 01:41:33  kirk
# Added 'messages' log processors
#
##########################################################################

########################################################
# 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 date from a logfile
# in the standard /var/log/messages format.

# I plan to add a *lot* more date flexibility at a later time...

if ( $ENV{'LOGWATCH_DATE_RANGE'} eq "yesterday") {
   $SearchDate = `/bin/date -d "1 day ago" +"%b %d"`;
}
elsif ( $ENV{'LOGWATCH_DATE_RANGE'} eq "today") {
   $SearchDate = `/bin/date +"%b %d"`;
}
elsif ( $ENV{'LOGWATCH_DATE_RANGE'} eq "all") {
   $SearchDate = "... ..";
}

# The date might be "Dec 09", but it needs to be "Dec  9"...
$SearchDate =~ s/ 0/  /;
chomp($SearchDate);

if ( $ENV{'LOGWATCH_DEBUG'} > 5 ) {
   print STDERR "DEBUG: Inside ApplyStdDate...\n";
   print STDERR "DEBUG: Range: " . $ENV{'LOGWATCH_DATE_RANGE'} . "\n";
   print STDERR "DEBUG: Looking For: " . $SearchDate . "\n";
}

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