Hi Monks, I finally suceeded in doing it. it works as expected. Script (my_script.pl) is given below.
#!/usr/bin/perl use strict; use warnings; use Time::Piece; use POSIX qw(strftime); my $format = '%b %e %T'; my $today = time; my $formatted_today = strftime "%b %e %T", ( localtime($today) ); my $yesterday = $today - 60 * 24 * 60; my $formatted_yesterday = strftime "%b %e %T", ( localtime($yesterday) + ); #print "VAR1 TODAY $today\n"; #print "VAR2 YESTERDAY $yesterday\n"; #print "\n"; #print "formatted_TODAY $formatted_today\n"; #print "formatted_YESTERDAY $formatted_yesterday\n"; #print "\n"; my $start = Time::Piece->strptime($formatted_yesterday, $format); my $end = Time::Piece->strptime($formatted_today, $format); print "VARIABLE END TODAY $end\n"; print "VARIABLE START YESTERDAY $start\n"; print "\n"; 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);
In reply to Re^6: 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: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |