Skip to main content

Oracle log monitoring from a shell script

I found this rather old article when looking up some shell scripting syntax. Occasionally there is gold to be found:

search_log.sh. A variety of logs are generated by Oracle products, and you might be interested in monitoring them. The database alert log contains messages that are critical to database operations. Log files are also generated when products are installed or deinstalled and when patches are applied. The following script iterates over a file passed to it as an argument. If any lines are found that contain ORA-, an e-mail message is sent to a designated recipient.
   
cat $1 | grep ORA- > alert.err if [ ‘cat alert.err|wc -l‘ -gt 0 ] then mail -s "$0 $1 Errors" administrator@yourcompany.com < alert.err fi
The specific test being performed is a count of the number of words that exist in the file alert.err, which is written when you redirect to alert.err. If the word count ( wc) is greater than ( -gt) zero, the contents of the if block will execute. In this case, you are using mail ( send mail might also be used) to send a message. The title of the message contains the script being executed ( $0), the name of the log being searched ( $1), and the lines that matched our initial search ( ORA-) as the body of the message.

Environmental variables such as ORACLE_HOME, ORACLE_BASE, and ORACLE_SID can be used to locate resources that are not in a fixed location in the Linux environment. If you are administering an Oracle E-Business Suite 11i application instance, you have numerous other environmental variables that can be used to locate resources. These include APPL_TOP, TWO_TASK, CONTEXT_NAME, and CONTEXT_FILE, to name a few. To see a complete list in your environment, execute the following command and examine the resulting file (myenv.txt):
env > myenv.txt
Various combinations of these environmental variables can be used as the location of a file being searched. For example, an alert log location might be designated as
   
$ORACLE_BASE/admin/$ORACLE_SID/bdump/alert_$ORACLE_SID.log

Based on the principles introduced in this script, a larger one can be written and scheduled to execute at periodic intervals that will search the contents of the alert log (or another file of interest) and send an e-mail if any errors exist. Then the contents of the log can be moved to another file, so that only the most recent error messages will be sent via e-mail.

Comments