A quick (and dirty?) way to mail Oracle alerts.


Tips and Tricks

Where I work, we have about 45 external Oracle Database Servers running RHEL 3. It’s a little tough keeping up with all of them day to day, so I made a quick BASH script that will check for any ORA- alerts in your Oracle alert_*.ora file. Here goes:
********************************
#!/bin/sh

tail -500 /usr/oracle/admin/ora_sid/bdump/alert_sid.log | grep ORA- > mailoraalerts.log
wc -l mailoraalerts.log > greporacount.txt
COUNT=`awk ‘{print $1}’ greporacount.txt`
if [ $COUNT -gt 0 ]; then
mail -s “Check ” your.address@mail.net < mailoraalerts.log
fi
********************************

So what this does is greps the last 500 lines of your alert log looking for ORA- string, and pipes that out to a log file. It then does a word count on that log file. If the word count is greater than 0 (there exists ORA- errors) then email me what the error is.

Then just schedule a cron job to run at whatever interval you desire. This probably isn’t the prettiest way to do this, I’d love to see other suggestions if anyone has any! My next step is to find out how to get Oracle to email me directly when there’s an error, instead of having cron determine when I am alerted.

Enjoy!


One Response to “A quick (and dirty?) way to mail Oracle alerts.”

  1. Doug Brown

    Only problem with an email coming from oracle is what if the database has crashed? You’ll see it in the alert log. I’m working on something that uses perl’s File::Tail module to consistently tail the alert log and when it encounters a predetermined error held in an array, shoot the on-call a page or email to a pager.

    Reply

Leave a Reply