Showing results for 
Search instead for 
Did you mean: 

Emailing alerts

Emailing alerts


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?

Honored Contributor

Re: Emailing alerts

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
Honored Contributor

Re: Emailing alerts


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

PS. Don't forget to modify lines:
a. DBA1=''
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)

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 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:


while (<>) {

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

Call it as:

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