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?In reply to Re^2: print lines withing specific date range from maillog file
by theravadamonk
in thread print lines withing specific date range from mailoog file
by theravadamonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |