Well, you really don't need Perl, cat, grep, cut, and awk all at the same time. One Perl script and a cron job can meet your requirements. One of the great things about Perl is the building blocks it provides natively, combined with those provided through the CPAN.

I would use Tie::File. It has a flock() method. If you're using that, it's a good idea to load the Fcntl module so that you have access to the ':flock' constants. You don't have to use Tie::File, but it is convenient, and can handle the locking for you. You could also use DBI along with DBD::CSV if you want to treat the logfile like a database, but that seems like overkill. Or you could just run through the file line by line writing out a tempfile, and then rename the tempfile over the original logfile.

Then use Text::CSV to grab the date field of each entry, one by one. Use Date::Manip (or some other similar module) to correctly parse and compare the date. If it's older than 14 days, delete that element from the tied array that represents the logfile.

Set up a cron job to cause the script to run once a week.

That's it, you're done.

Let us know if you need help with some aspect of putting the building blocks together.


Dave


In reply to Re: Help - Deleting a log line with a data older than 14 days by davido
in thread Help - Deleting a log line with a data older than 14 days by Roshan_2004

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.