Re: Windows scripts requirement!!!

From: Jared Still <>
Date: Mon, 16 Mar 2009 14:36:00 -0700
Message-ID: <>

On Sun, Mar 15, 2009 at 7:28 AM, edwin devadanam <>wrote:

> 1)database and listener up and down status
> 2)alert log scan

I personally recommend the scripts from this book:


Scripts and PDBA libs can be found here as well:

Very effective, but not trivial to setup.

Then again, what you are asking for is never trivial to setup if it is also robust.

3)alert log rename

The Perl script at the end of this post works quite nicely for #3. It works in Windows (ActiveState Perl) and *nix.

Just change the value of the $sourceLog variable

The variable $daysToKeepLog determines how old a zipped up log file must be before it is deleted.

Jared Still
Certifiable Oracle DBA and Part Time Perl Evangelist

#!/home/oracle/perl/bin/perl -w

use strict;
use File::Find ();
use File::Basename;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

my ($logPrefix, $logSuffix ) = qw{alert_ .zip}; my $daysToKeepLog = 90;
my $sourceLog = 'I:\oracle\QAS\saptrace\background\alert_qas.log';

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year += 1900;
my $date = sprintf("%4d-%02d-%02d.%02d-%02d-%02d", $year,$mon,$mday,$hour,$min,$sec);
my $targetZip = qq{${sourceLog}.${date}.zip};

my $zip = Archive::Zip->new();
my $member = $zip->addFile($sourceLog);

die 'logmgr write error' unless $zip->writeToFileNamed($targetZip) == AZ_OK;

open(LOG, ">$sourceLog") || die "cannot open $sourceLog for write - $! \n"; print LOG qq{ \n};
close LOG;

# delete old logs if needed > 90 days
# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.

# for the convenience of &wanted calls, including -eval statements: use vars qw/*name *dir *prune/;

*name   = *File::Find::name;
*dir    = *File::Find::dir;
*prune  = *File::Find::prune;

# Traverse desired filesystems
# a delete the old files

File::Find::find({wanted => \&wanted}, dirname($sourceLog)); exit;

sub wanted {

    my ($dev,$ino,$mode,$nlink,$uid,$gid);

    (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&     -f _ &&
    (int(-M _) > $daysToKeepLog) &&
     /^$logPrefix.*$logSuffix\z/s &&
    (unlink($_) || warn "$name: $!\n");

Received on Mon Mar 16 2009 - 16:36:00 CDT

Original text of this message