Hi all,

Oracle core dumps are created as directories. I want to remove these
directories after a certain period of time, for example 10 days.

I have the following script that searches a directory for files that are
older than 10 days and possibly remove them. At the moment, for the sake of
testing, am printing them out for the meantime.

While the code below seems to work, it also include the main directory as
well in the deletion, can someone advise how I can exclude that from the
deletion?

Also, does anyone have an example where the list of directories to search
and remove for can be read from some kind of an INI file, instead of having
it hardcoded as below in the my $dir line? At the moment, am thinking of
creating some sort of an INI file that I read in a while loop and run the
opendir and remove/unlink accordingly.

Any feedback will be very much appreciated. Thanks ...

my $dir = '/u01/oradump/TESTDB/cdump';
opendir(DIR,$dir) || die "Can't open $dir : $!\n";
my @files = readdir(DIR);
close(DIR);

foreach my $file(@files)
{
my $now = time;
my @stat = stat("$dir/$file");
if ($stat[9] < ($now - 864000))
{
print "Deleting $dir/$file...";
#unlink("$dir/$file");
print "Done.\n";
}

}

Sample output as below;

Deleting /u01/oradump/TESTDB/cdump/....Done.
Deleting /u01/oradump/TESTDB/cdump/core_7571...Done.
Deleting /u01/oradump/TESTDB/cdump/core_5705...Done.
Deleting /u01/oradump/TESTDB/cdump/core_15043...Done.
Deleting /u01/oradump/TESTDB/cdump/core_25662...Done.
Deleting /u01/oradump/TESTDB/cdump/core_29081...Done.
Deleting /u01/oradump/TESTDB/cdump/core_907...Done.
Deleting /u01/oradump/TESTDB/cdump/core_3853...Done.
Deleting /u01/oradump/TESTDB/cdump/core_19062...Done.
Deleting /u01/oradump/TESTDB/cdump/core_11675...Done.
Deleting /u01/oradump/TESTDB/cdump/core_24237...Done.
Deleting /u01/oradump/TESTDB/cdump/core_1939...Done.

Reply via email to