1748038 Members
4929 Online
108757 Solutions
New Discussion юеВ

Re: Emailing alerts

 
Brian Gebhard_1
Advisor

Emailing alerts

Hello,

I'm trying to set up a background job that would email me when the alert.log received an error msg. I've been trying to use tail -f |grep 'ORA-' but it appears the 'mail' command only works when an EOF is issued. So I never get emails until the process is terminated. I didn't want to have a process run each minute or so and email me the last 10-20 lines of the alert.log because on slow periods the alert.log might not grow enough. Does anyone have any suggestions?

thanks
4 REPLIES 4
Victor BERRIDGE
Honored Contributor

Re: Emailing alerts

Hi,
You could write a script which
1) touch toto
2)does a tail ora.log>titi then compares titi with the previous toto and if different send you via email and renames titi to toto...
Then you execute your script as a cron job

All the best
Victor
Yogeeraj_1
Honored Contributor

Re: Emailing alerts

hi,

I use the following:

Filename: alerts.ksh (attached)
Description: Automatic monitoring of the production database's ALERT LOG file for exceptions.

Running it as the Oracle User, reschedules daily execution of script - morning, evening and night everyday (uses at)

Makes monitoring of the Alert log easy task!

Hope this helps!

Best Regards
Yogeeraj

PS. Don't forget to modify lines:
a. DBA1='myname@mymailserver.mu'
b. SID=pfs

to suit your own enviroment
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Brian Gebhard_1
Advisor

Re: Emailing alerts

Well thank you both but it's not exactly what I'm looking for. I'm trying to set something up that notifies me the moment the ORA- is written to the alert_$SID.log. Both solutions are based on a cron job interval time. Granted I could set up a cron job to run each minute but I was hoping there's a way to use tail of some other function to email me instead of displaying the information on the terminal like tail -f does.

tail f- $ORACLE_BASE/admin/$SID/bdump/alert_$SID.log |grep 'ORA-'

This just displays any new lines in the alert.log to my screen. It won't go to the email until I terminate the process. So I believe 'mail' looks for a EOF character before it sends the msg. At the moment I'm using the alert oracheck.run script that compes with the statspack. This is based on a job interval also.
Bill Douglass
Esteemed Contributor

Re: Emailing alerts

Something like the following will work:

#!/path/to/your/perl

while (<>) {

if (/ORA-/) {
open $ML, "|/usr/bin/mailx -s 'ORACLE Alert' user@domain.com";
print $ML $_;
close $ML;
}
}


Call it as:

tail -f /path/to/oracle.log | perlscript.pl