#!/usr/bin/perl -w
use strict;
##########################################################################
# $Id: applydate,v 1.6 2003/01/13 03:22:34 kirk Exp $
##########################################################################

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

use POSIX qw(strftime);

# SearchDate2 is for newer crond (i.e. RH7.X)
my ($SearchDate, $SearchDate2, $ThisLine);
my ($incount, $outcount) = (0, 0);
my $time = time;

if ($ENV{'LOGWATCH_DATE_RANGE'} eq 'yesterday') {
   $SearchDate = strftime("%m/%d", localtime($time-86400));
   $SearchDate2 = strftime("%b %e", localtime($time-86400));
}
elsif ($ENV{'LOGWATCH_DATE_RANGE'} eq 'today') {
   $SearchDate = strftime("%m/%d", localtime($time));
   $SearchDate2 = strftime("%b %e", localtime($time));
}
elsif ($ENV{'LOGWATCH_DATE_RANGE'} eq 'all') {
   $SearchDate = '../..';
   $SearchDate2 = '... ..';
}

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

while (defined($ThisLine = <STDIN>)) {
   $incount++;
   if ($ThisLine =~ m/^[^ ]+ \($SearchDate-..:..:..-[0123456789]+\) /o) {
      print $ThisLine;
      $outcount++;
   } elsif ($ThisLine =~ m/^$SearchDate2 ..:..:.. [^ ]+ \w+\[\d+\]:/o) {
      print $ThisLine;
      $outcount++;
   }
}

if ($ENV{'LOGWATCH_DEBUG'} > 5) {
   print STDERR "DEBUG: ApplyDate (cron): $incount Lines In, $outcount Lines Out\n";
}

