Operating System - HP-UX
1821984 Members
3279 Online
109638 Solutions
New Discussion

Perl Code help to clean up log files older than 7 days,

 
SOLVED
Go to solution
Becke
Super Advisor

Perl Code help to clean up log files older than 7 days,

Guys
Question for a perl guru, Below is my perl code to clean logfiles older than 7 days, could you please modify my code so it prints files to a log file instead of printing it to standard out and then deletes files older than seven daysit.. please modify my code below

use strict;

my $today = time;
my $dir = '.';

opendir DIR, $dir or die "opendir '$dir':"
while (my $file = readdir DIR) {
next if -d "$dir/$file";
my $mtime = (stat "$dir/$file") [9];
if ($today - 86400 * 7 > $mtime) {
print "$dir/$file is older than 7 days\n";
}
}
closedir DIR;

#END

Could you please modify the above code so it prints the file to a log file instead of printing it to standard out before it deletes it, and then it deletes the files older than 7 days
1 REPLY 1
Arunvijai_4
Honored Contributor
Solution

Re: Perl Code help to clean up log files older than 7 days,

Hi Raf,

Your previous thread and this one are same ? Check Procura's reply in your thread.

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1001991

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"