File: applystddate

package info (click to toggle)
logwatch 5.2.2-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,112 kB
  • ctags: 42
  • sloc: perl: 9,032; sh: 65; makefile: 54
file content (54 lines) | stat: -rwxr-xr-x 1,821 bytes parent folder | download
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
#!/usr/bin/perl -w
##########################################################################
# $Id: applystddate,v 1.12 2002/10/14 16:21:57 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);

# 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("%b %d", localtime($time-86400));
}
elsif ( $ENV{'LOGWATCH_DATE_RANGE'} eq 'today') {
   $SearchDate = strftime("%b %d", localtime($time));
}
elsif ( $ENV{'LOGWATCH_DATE_RANGE'} eq 'all') {
   $SearchDate = "... ..";
}

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

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;
   } elsif ($ThisLine =~ m/(Mon|Tue|Wed|Thu|Fri|Sat|Sun) $SearchDate ..:..:.. \d{4}/o) {
      print $ThisLine;
   } #Debian - specific: the syslogd restart
     elsif ($ThisLine =~ m/^$SearchDate ..:..:.. [^ ]* [^ :]* [0-9#.]+: /o) {
      print $ThisLine;
   }
}