Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Perl Script for Alert Log

Perl Script for Alert Log

From: Smith, Ron L. <rlsmith_at_kmg.com>
Date: Mon, 30 Jul 2001 13:59:31 -0700
Message-ID: <F001.00359668.20010730135028@fatcity.com>

A few weeks ago I was looking for a script that would combine the date records with the detail records on the Oracle alert_log. I didn't get any responses so I decided to do it myself. (I hate it when that happens!). Anyway, everyone here tells me how great Perl is at handling things like this so I bought a book and wrote a short Perl script. The book was great and the script does what it was supposed to do so I thought I would pass it along. Please don't critisize my poor coding. It works!  

The perl script is actually called by another script that looks in /etc/oratab and figures out where the OORACLE_BASE and thus the alert_log is located. The script combines the records into an output file and then returns control to the calling program. The calling program does a grep on the combined records looking for ORA, etc... errors and sends an email if they are found.  

Hope someone else can use this.  

Ron Smith
Database Administrator
rlsmith_at_kmg.com  

#!/usr/local/bin/perl
$eNV{"PATH"} = "/bin:/usr/bin:/usr/local/bin"; # for security reasons
$ENV{"SHELL"} = "/usr/bin/sh";  

$inlog = $ARGV[0];
shift(@ARGV);
$sid = $ARGV[0];  

unless (open(LOGOUT, ">$sid.temp.alert.log")) {

        die ("Cannot open output log file\n");
        exit 8;

}  

if (open(LOGIN, "$inlog")) {

        $line = <LOGIN>;
        $dateline = "No Date";
        $sdateline = "No Date";
        while ($line ne "" ) {
                $abbrev = substr ($line, 0, 3);
                if ($abbrev eq "Mon") {

$dateline = $line;
$sdateline = $line;
} elsif ($abbrev eq "Tue") {
$dateline = $line;
$sdateline = $line;
} elsif ($abbrev eq "Wed") {
$dateline = $line;
$sdateline = $line;
} elsif ($abbrev eq "Thu") {
$dateline = $line;
$sdateline = $line;
} elsif ($abbrev eq "Fri") {
$dateline = $line;
$sdateline = $line;
} elsif ($abbrev eq "Sat") {
$dateline = $line;
$sdateline = $line;
} elsif ($abbrev eq "Sun") {
$dateline = $line;
$sdateline = $line;
} else { select (LOGOUT);
$~ = "OUTREC";
write; } $dateline = $sdateline; $line = <LOGIN>; $abbrev = " "; }

}  

format OUTREC =

^<<<<<<<<<<<<<<<<<<<<<<<<
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<<<<<<<<<<
<<<<<<<<
$dateline $line
.
exit 0
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Smith, Ron L.
  INET: rlsmith_at_kmg.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Mon Jul 30 2001 - 15:59:31 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US