1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#!/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;
}
}
|