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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#!/usr/bin/perl -w
use strict;
##########################################################################
# $Id: applydate,v 1.10 2004/06/21 13:57:12 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;
my $hostname = `hostname`;
my $OSname = `uname -s`;
chomp $hostname;
chomp $OSname;
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++;
#Solaris CRON filter -mgt
#Basically takes the cron format in /var/cron/log and makes it look like syslog
if ( $OSname =~ /SunOS/ ) {
if ($ThisLine =~ m/^\>\s+CMD: (.+)$/o) {
my $command = $1;
my $nextline = <STDIN>;
my ($user, $ps, $datestamp) = $nextline =~ /^\>\s+(\w+) (\d+) \w \w\w\w (\w\w\w\s+\d+ \d\d:\d\d:\d\d)/;
$ThisLine = "$datestamp $hostname CROND[$ps]: ($user) CMD ($command)\n";
}
}
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";
}
|