Re: file alert

  • From: Jared Still <jkstill@xxxxxxxxx>
  • To: oracledbam@xxxxxxxxxxx
  • Date: Mon, 4 Oct 2004 11:54:44 -0700

On Mon, 04 Oct 2004 12:19:47 -0400, Seema Singh <oracledbam@xxxxxxxxxxx> wrote:
> Hello,
> I want to setup scripton linux whenever alert log >1GB we have to get
> alert.Does anyone send similar kidn of script ?
> when I'm executing following command its show error
> 

Here is a perl script that will create a zip of the current log, then
truncate the file.  

Archived alert logs are deleted after 90 days by default.

Modify the  $daysToKeepLog and $sourceLog variables to suit.

Note: the 'wanted' subroutine is generated via find2perl

-- 
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 ($logPrefix1, $logPrefix2, $logSuffix ) = qw{alert ALRT .zip};
my $daysToKeepLog = 90;
my $sourceLog = '/u01/app/oracle/admin/dv01/bdump/alert_dv01.log';

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$mon++;
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) &&
        (
                /^.*$logPrefix1.*$logSuffix\z/s
                ||
                /^.*$logPrefix2.*$logSuffix\z/s
        ) &&
        (unlink($_) || warn "$name: $!\n");
}
--
//www.freelists.org/webpage/oracle-l

Other related posts: