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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.