Newbie Question on Deleting Logs Script

C

Clifford Bracht

I was asked to create a Perl script that is able to when it runs
delete Performance logs that are 30 days old from the current date on
a Windows Platform. I didn't know Pearl prior to this and this is
only after about 5 days of trying to teach myself. Here is my code. I
was just wondering if anyone could lend some helpful suggestions that
could maybe clear things up or get me going on the right path if I'm
not already there. Thanks

use Date::Calc qw:)all);

eval
{
($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = System_Clock();
};

#$days = Date_to_Days($year,$month,$day);
#($year,$month,$day) = Add_Delta_Days(1,1,1, $days - 1);
$day_diff = Delta_Days($year1, $month1, $day1, $year2, $month2,
$day2);
$checkdate ($year1, $month1, $day1) = (@logdate); #Date Associated
with the first or oldest perflog file
$currentdate ($year2,$month2, $day2) = (Today([$gmt]); #Current Date
$counterlog = ("C:\PerfLogs\system\");
$tracelog = ("C:\PerfLogs\system\"); #Directory of the log files
$alertlog = ("C:\PerfLogs\system\");


@logarray("$counterlog","$tracelog","$alertlog",); #Array of the
three performance logs
@logdate("$logdate1","$logdate2","$logdate3",)


if (($year,$month,$day) = Decode_Date_US($counterlog);
{
$counterlog = $logdate1;
}
else if
{
(($year,$month,$day) = Decode_Date_US($tracelog);
$tracelog = $logdate2;
}
else if
{
(($year,$month,$day) = Decode_Date_US($tracelog);
$alertlog = $logdate3;

}
else
{
exit;
};
#Reads in each Performance counter and checks the difference in days
against 30 days

for ($logcounter = 0; logcounter <= $#logarray; logcounter++)
{
while ($day_diff >= 30)
{
delete $checkdate;
}
else
print "All files are current; No log files where deleted \n";
}

exit;
 
A

Anno Siegel

Clifford Bracht said:
I was asked to create a Perl script that is able to when it runs
delete Performance logs that are 30 days old from the current date on
a Windows Platform. I didn't know Pearl prior to this and this is
only after about 5 days of trying to teach myself. Here is my code. I
was just wondering if anyone could lend some helpful suggestions that
could maybe clear things up or get me going on the right path if I'm
not already there. Thanks

Your code (now snipped) is beyond repair.

You are much too concerned about the date calculations. Perl has
a file test operator "-M" that returns the age of a file (time since
last modification, "perldoc -f -X" for details) in days directly.
So, to decide if a file whose name is in $file should be deleted,
just do

delete $file if -M $file >= 30;

To find the candidates in the first place, use the File::Find module.
See "perldoc File::Find" for more.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top