
Installgen
Features and Benefits
Installgen
Demo Available for download...
Bookmark This Page

#! /usr/local/bin/perl
# script: c:\server_scripts\rotateoraclefiles.pl (renamed from 13_win_rotateoraclefiles_1.pl)
# Features: This perl script runs nightly via AT job to remove/rotate Oracle files.
#
# ******** Rotate Server logs nightly at 11:55PM ********
# AT 23:55 /every:M,T,W,Th,F,S,Su c:\server_scripts\rotateoraclefiles.pl
# Used By: run automatically via AT scheduler
# Copyright 2002 by .com Solutions Inc.
#
# ---------------------- Revision History ---------------
# Date By Changes
# 11-30-2001 dsimpson Created perl script version for use on Windows NT/2000 servers.
# 12-27-2001 dsimpson Added ORACLE_SID environment variable
# 07-11-2002 dsimpson Corrected ORACLE_HOME pathnames.
# Replaced rotation of dbsnmpc.log and dbsnmpw.log
# files with dbsnmp.log files (for Oracle 9i).
# Added rotation of agntsrvc.log file rotation.
# Added stopping of intelligent agent and stopping only the listener
# logging (without stopping the listener itself) during log
# rotations.
# Added rotation of Oracle(Oracle Home Name)Agent.nohup file.
#
# This output file was created by Installgen version 1.38 on Thu Nov 14 17:16:25 2002. By .com Solutions Inc. www.dotcomsolutionsinc.net
use strict;
use File::Find;
# insure that environment variable is used by this perl script
$ENV{'ORACLE_SID'} = "PROD3";
my $file_to_delete='';
my $file_to_rotate='';
my $tempfile='';
my $full_name='';
sub files_to_remove
{
# get items over 7 days old, but avoid deleting directory pointers '.' and '..'
if ( -M $_ > 7 && $_ ne "." && $_ ne "..")
{
# avoid deleting directories - just delete files
$file_to_delete=$_ if !-d $_;
print "deleting file: $file_to_delete\n";
unlink ($file_to_delete);
}
}
# Remove old Oracle backup files in c:\backup directory after 7 days
find (\&files_to_remove, 'c:\backup');
# Remove old Oracle archivelog files in c:\archive directory after 7 days
# There should only be current archivelog files for today if backups are working correctly
find (\&files_to_remove, 'c:\archive');
# Remove Oracle bdump,cdump,udump files after 7 days
find (\&files_to_remove, 'c:\u01\bdump');
find (\&files_to_remove, 'c:\u01\udump');
#find $ORA_CDUMP_DIR -mtime +7 -exec rm -R {} ;
find (\&files_to_remove, 'c:\u01\cdump');
# need to also remove core dump directories older than 7 days old from c:\u01\cdump
my $dir_name = "c:\\u01\\cdump";
opendir DIR,$dir_name;
my @filename = readdir DIR;
closedir DIR;
foreach $tempfile (@filename)
{
$full_name = $dir_name . "\\" . $tempfile;
if (-d $full_name && $tempfile ne "." && $tempfile ne ".." )
{
print "sub-directory name is: $full_name " if -M $full_name > 7;
rmtree ("$full_name",1,1);
}
}
# turn off listener logging while rotating log file
system ("lsnrctl set log_status off");
# stop the intelligent agent while rotating log file
system ("agentctl stop");
# Rotate the Oracle listener.log log file nightly
$file_to_rotate="c:\\v901"."\\network\\log\\"."listener.log";
rename ($file_to_rotate.".5",$file_to_rotate.".6");
rename ($file_to_rotate.".4",$file_to_rotate.".5");
rename ($file_to_rotate.".3",$file_to_rotate.".4");
rename ($file_to_rotate.".2",$file_to_rotate.".3");
rename ($file_to_rotate.".1",$file_to_rotate.".2");
rename ($file_to_rotate.".0",$file_to_rotate.".1");
rename ($file_to_rotate,$file_to_rotate.".0");
# Rotate the Oracle dbsnmp.log log file nightly
$file_to_rotate="c:\\v901"."\\network\log\\"."dbsnmp.log";
rename ($file_to_rotate.".5",$file_to_rotate.".6");
rename ($file_to_rotate.".4",$file_to_rotate.".5");
rename ($file_to_rotate.".3",$file_to_rotate.".4");
rename ($file_to_rotate.".2",$file_to_rotate.".3");
rename ($file_to_rotate.".1",$file_to_rotate.".2");
rename ($file_to_rotate.".0",$file_to_rotate.".1");
rename ($file_to_rotate,$file_to_rotate.".0");
# Rotate the Oracle agntsrvc.log log file nightly
$file_to_rotate="c:\\v901"."\\network\\log\\"."agntsrvc.log";
rename ($file_to_rotate.".5",$file_to_rotate.".6");
rename ($file_to_rotate.".4",$file_to_rotate.".5");
rename ($file_to_rotate.".3",$file_to_rotate.".4");
rename ($file_to_rotate.".2",$file_to_rotate.".3");
rename ($file_to_rotate.".1",$file_to_rotate.".2");
rename ($file_to_rotate.".0",$file_to_rotate.".1");
rename ($file_to_rotate,$file_to_rotate.".0");
# Rotate the Oracle Oraclev9012Agent.nohup log file nightly
$file_to_rotate="c:\\v901"."\\network\\log\\"."Oraclev9012Agent.nohup";
rename ($file_to_rotate.".5",$file_to_rotate.".6");
rename ($file_to_rotate.".4",$file_to_rotate.".5");
rename ($file_to_rotate.".3",$file_to_rotate.".4");
rename ($file_to_rotate.".2",$file_to_rotate.".3");
rename ($file_to_rotate.".1",$file_to_rotate.".2");
rename ($file_to_rotate.".0",$file_to_rotate.".1");
rename ($file_to_rotate,$file_to_rotate.".0");
# Rotate the Oracle nmiconf.log log file nightly
$file_to_rotate="c:\\v901"."\\network\\log\\"."nmiconf.log";
rename ($file_to_rotate.".5",$file_to_rotate.".6");
rename ($file_to_rotate.".4",$file_to_rotate.".5");
rename ($file_to_rotate.".3",$file_to_rotate.".4");
rename ($file_to_rotate.".2",$file_to_rotate.".3");
rename ($file_to_rotate.".1",$file_to_rotate.".2");
rename ($file_to_rotate.".0",$file_to_rotate.".1");
rename ($file_to_rotate,$file_to_rotate.".0");
# Rotate the Oracle sqlnet.log log file nightly
$file_to_rotate="c:\\v901"."\\network\\log\\"."sqlnet.log";
rename ($file_to_rotate.".5",$file_to_rotate.".6");
rename ($file_to_rotate.".4",$file_to_rotate.".5");
rename ($file_to_rotate.".3",$file_to_rotate.".4");
rename ($file_to_rotate.".2",$file_to_rotate.".3");
rename ($file_to_rotate.".1",$file_to_rotate.".2");
rename ($file_to_rotate.".0",$file_to_rotate.".1");
rename ($file_to_rotate,$file_to_rotate.".0");
# turn on listener logging
system ("lsnrctl set log_status on");
# re-start intelligent agent
system ("agentctl start");

