xblue,
You've saved me a lot of time - thanks very much! Here's my script. If you could pass your eye over it, then I'd appreciate it. The script is used to clear out Oracle Archived Redo Log files that are more than 48 hours old (I back these up onto tape and so only need the most recent to be on-line). The script is rather messy, but I reckon it works! I'll run this script from a batch file every night (I used PHP instead of something 'more suitable' because I've just learned it and this helps me build my skills in PHP - I could have written this in KiXtart but, let's face it, PHP is far sexier!).
<?php
//Directory where our files to archive are
$DirectoryToProcess="d:\oracle\oradata\prd1\arch";
$LogFile="d:\oracle\oradata\prd1\admin\arch_arch.log";
$FileHandle=fopen($LogFile, "a+");
$today = getdate();
$month = $today['month'];
$mday = $today['mday'];
$year = $today['year'];
$hours = $today['hours'];
$minutes = $today['minutes'];
$seconds = $today['seconds'];
$FormattedDate=$mday."-".$month."-".$year." ".$hours.":".$minutes.":".$seconds;
fwrite($FileHandle, "\nstarted processing archived redo logs at: ".$FormattedDate."\n");
//open directory to create object
$DirectoryListing=dir($DirectoryToProcess);
//get each entry
while( $FileName = $DirectoryListing->read() )
{
//check created time
if ($FileName != "." && $FileName != "..")
{
$FileSpec=$DirectoryToProcess."\".$FileName;
$FileMTime=filemtime($FileSpec);
echo "Created date for ".$FileName." is ".$FileMTime."\n";
$CurrentTime=mktime();
echo "Current time is: ".$CurrentTime."\n";
echo "Difference is: ".$CurrentTime-$FileMTime."\n";
$NoOfHoursOld=(($CurrentTime-$FileMTime)/(60*60));
echo "This is the following number of hours: ".$NoOfHoursOld."\n";
if ($NoOfHoursOld > 48)
{
//delete the file
fwrite($FileHandle, "\nattempting to delete file: ".$FileSpec."\n");
if (unlink($FileSpec))
{
//delete was successful
fwrite($FileHandle, "\ndelete successful!");
}
else
{
//could not delete file
fwrite($FileHandle, "\ndelete failed!");
}
}
}
}
fwrite($FileHandle, "\nfinished processing archived redo logs at: ".$FormattedDate."\n");
fclose($FileHandle);
//close the directory
$DirectoryListing->close()
?>
Unless there's anything obviously wrong with this script, then that's that - thanks very much!
cheers,
Pollocks