in reply to Re: print lines withing specific date range from maillog file
in thread print lines withing specific date range from mailoog file
I hardcoded below 2 things.#!/usr/bin/perl use strict; use warnings; use Time::Piece; my $format = '%b %e %T'; my $start = Time::Piece->strptime('Feb 1 10:30:00', $format); my $end = Time::Piece->strptime('Feb 2 10:30:00', $format); open(FILE, "/var/log/maillog") or die "Couldn't open maillog: $!; abor +ting"; while (<FILE>) { my ($timestamp) = /(^\w+\s+\d+\s+\d\d:\d\d:\d\d)/; my $t = Time::Piece->strptime($timestamp, $format); print if $t >= $start && $t <= $end; } close(FILE);
my $start = Time::Piece->strptime('Feb 1 10:30:00', $format); my $end = Time::Piece->strptime('Feb 2 10:30:00', $format);
Now I want system to fill today's date and yesterday's date? instead of Feb 16 and Feb 17
I want system to fill Mar 16 and Mar 17Time range (10.30 to 10.30) is OK. I can hardcode it.
Any comment?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: print lines withing specific date range from maillog file
by Corion (Patriarch) on Mar 17, 2016 at 12:03 UTC | |
by theravadamonk (Scribe) on Mar 28, 2016 at 11:30 UTC | |
by Corion (Patriarch) on Mar 28, 2016 at 11:45 UTC | |
by theravadamonk (Scribe) on Mar 30, 2016 at 11:35 UTC |