in reply to Help - Deleting a log line with a data older than 14 days

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