...
For example, create the file /etc/logwatch/scripts/logfiles/charon/applydate with the following content (as an existing applydate script was used as template, the copyright must be preserved):
Div |
---|
|
########################################################
#########################################################
use POSIX qw(strftime);
use Logwatch ':dates';
my ($SearchDate, $ThisLine);
my ($incount, $outcount) = (0, 0);
my $time = time;
my $hostname = $ENV{'HOSTNAME'};
my $OSname = $ENV{'OSname'};
$SearchDate = TimeFilter("%y%m%d:%H%M%S");
my $all = 0;
while (defined($ThisLine = <STDIN>)) {
$incount++;
if ($SearchDate =~ m/\.+/) {
$SD = $SearchDate;
$SD =~ s/\(//g;
@SDPARTS = split (':',$SD);
$datepart1 = $SDPARTS[0];
if ($all == 1) {
print $ThisLine;
$outcount++; }
# if date is the same, print line if time is greater or equal to
# search time
elsif ($ThisLine =~ m/^\d+($datepart1):(\d{0,6})/) {
$linedate = $1.':'.$2;
if ($linedate ge $SD) {
print $ThisLine;
$outcount++; }
|
} # else, if date is larger than search date, print all lines from here on
elsif ($ThisLine =~ m/^\d{2}(\d{6}):/) {
if ($1 gt $datepart1) {
print $ThisLine;
$outcount++;
$all = 1; }
} } }
|
Please note: the script above does not cover all parameters possible for the range parameter of logwatch. It is provided only as an example for informational purposes.
...