Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Searching the Alert log file
Peter Wales wrote:
> > John Hough wrote: > > > Does anyone have a script that searches the alert log for > > pre-defined > > errors and e-mails a distribution list is errors occur. A script > > written in PERL would be perfect since we have to run this on unix, > > NT and VMS.
Here is what I have, using perl.
monitor_alert_log file is set to run as a cron job. It monitors the alert log and emails all error lines to the Oracle user. It emails only the error lines, while making sure that the lines don't repeat.
#!/usr/local/bin/perl
#
# This is a cron job that scans the alert log file for error messages
# and mails them to the oracle user.
#
# The trick is to scan only the last set of lines in the alert log file
and
# not to repeat checking the same part. This is accomplished by keeping
# track of the number of lines the file had last time the script
executed.
# This number is kept in a file .monitor_alert_log.LINE_COUNT, and
# subsequent scans are done on the difference between this number and
the
# total line number in the file at execution time.
#
# Uses ~oracle/scripts/perl/common_set_oracle_env which sets all the
# required Oracle env variables.
#
# By: Simon Goland
# On: Feb 19, 1997
#
# Processes that run as a crontab entry inherit a very impoverished
environment.
# Therefore set all possible related environment variables explicitly.
#
require
"/export/share/vol07/app/oracle/scripts/perl/common_set_oracle_env";
chdir $ENV{"ORACLE_BASE"}."/scripts/crons" || die "Cannot chdir: ".$ENV{"ORACLE_BASE"}."/scripts/crons";
$alertFile = $ENV{"ORACLE_BASE"}."/admin/ldbc/bdump/alert_ldbc.log"; $oldLineCountFile = ".monitor_alert_log.LINE_COUNT"; $oldLineCount = 0; $newLineCount = 0;
# Get the last line count (last execution) of the alert log file.
#
open( FILE, $oldLineCountFile ) || die "Cannot find file:
$oldLineCountFile\n";
$oldLineCount = <FILE>;
close( FILE );
# Get the new line count for the alert log file.
#
open( WC, "wc -l $alertFile |" );
while( <WC> ) {
@aLine = split;
$newLineCount = @aLine[0]; # line count is the first
element
}
close( WC );
# Find the difference between the last count of lines in alert log file
# and the present count. This will be the parameter to the 'tail'
command.
# Store all resulted lines in an array for later search for errors.
#
$diff = $newLineCount - $oldLineCount;
open( TAIL, "tail -$diff $alertFile | egrep \'(^Errors|^ORA\-)\' |" );
@allLines = <TAIL>;
close( TAIL );
# Save the latest line count to file (to be used next time).
#
open( OUTFILE, ">$oldLineCountFile" );
print OUTFILE $newLineCount;
close( OUTFILE );
# If any error lines found, add some statistics (line counts) and email
the
# whole thing to 'oracle', including execution the date/time.
#
if( $#allLines > 0 ) {
$el = $#allLines + 1; $stats = "Line count on last check: $oldLineCount\n"; $stats = $stats."Line count on this check: $newLineCount\n"; $stats = $stats."Error lines : $el";push( @allLines, "\n$stats" );
open( MAIL, "| mailx -s \"Errors in Alert Log file\" oracle" );
print MAIL @allLines;
close MAIL;
}
# end
The file to set common variables looks like that
$ENV{'ORACLE_HOME'} =
"/export/share/vol07/app/oracle/product/7.3.2";
$ENV{'ORACLE_BASE'} = "/export/share/vol07/app/oracle";
...
Hope that helps. If you have more questions, let me know.
-- [ Simon Goland B-)> sg_at_mda.ca ] [ Without action there is no change ]Received on Tue Apr 15 1997 - 00:00:00 CDT
![]() |
![]() |