Wednesday, October 27, 2010

Redo log switch report from alert.log

Redo log file switch Report from alert.log using perl script


1. setup database environment
2. export ALERT=

example :
export ALERT=/ora01/oracle/admin/demo/alert_demo.log

3. execute following script

$ perl readalert.pl

Script readalert.pl

# readalert.pl
#!/usr/local/bin/perl -w
# Description : This is the program to analyze the alert log
#               file and print out diagnostics.

format top =
                 LOG SWITCH REPORT
                 +++++++++++++++++
 Time                                    Sequence
 __________________                      _____________
.
format STDOUT =
@<<<<<<<<<<<<<<<<<<                      @<<<<<<<<<<<<
substr("$TEST",3,13), $SEQ[$#$SEQ]
.
if ( ! $ENV{"ALERT"} ) {
  print "Set enviornment variable ALERT to Alert Log file location ! \n";
  exit(1);
}

open (FH,$ENV{"ALERT"});
while () {
    if (/Mon|Tue|Wed|Thu|Fri|Sat|Sun/) {
       $TEST = $_;
       next;
    }
    # This is global variable , Global because we use it in format statement
    # Convert Input line into array and print last element which is sequence number
    # $var[$#$var] is like $NF in awk
    @SEQ = split / /;
    write if /Thread.*advanced/;

}
close(FH);


Hope this helps. Regards Rupam