#!/usr/bin/perl -w

########################################################
# This was stolen from code written and is maintained by:
#    Kirk Bauer <kirk@kaybee.org>
#
########################################################

use POSIX qw(strftime);

# 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...

my $time = time;

if ( $ENV{'LOGWATCH_DATE_RANGE'} eq 'yesterday') {
   $SearchDate = strftime("%d/%b/%Y", localtime($time-86400));
}
elsif ( $ENV{'LOGWATCH_DATE_RANGE'} eq 'today') {
   $SearchDate = strftime("%d/%b/%Y", localtime($time));
}
elsif ( $ENV{'LOGWATCH_DATE_RANGE'} eq 'all') {
   $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:..:..:../o) {
      print $ThisLine;
   }
}

