A shell script to archive and clean your alert log

Here is a quick Unix shell script you can use to archive and clean your Oracle alert log.

Here is a quick UNIX shell script you can use to archive and clean your Oracle alert log. If you manage an actively changing database, you are well aware that your alert log can grow to unmanageable sizes. Running this script on a regular basis will help you manage the size of your alert logs. The script copies the alert log, sets the log to zero bytes (without changing the inode of the file), and compresses the copied file. Since writing...

and deploying this script, I no longer have to go through huge alert logs in order to see the lastest entries. I also do not have to worry about the logs get ting too large.

You might have to change some of the environment variables for your environment (and you might have to set your PATH environment variable), but this should work fine on OFA compliant UNIX servers. I occasionally run this on multiple database instances on multiple Sun Solaris servers so that my alert logs do not become unreadable. The versions of Oracle which I have used this on are 7.3.2 up to 9.0.2 running on Sun Solaris servers.

#!/usr/bin/sh

#SET SHELL VARIABLES
HOSTNAME=`/usr/bin/uname -n`; export HOSTNAME
WHO_AM_I=`who am i | awk '{print $1}'`; export WHO_AM_I
BASE_DIR=`cat /etc/passwd | grep $WHO_AM_I":" | awk -F: '{print $6}'`; export BASE_DIR
LOG_DIR=$BASE_DIR/admin/$ORACLE_SID/bdump; export LOG_DIR
TODAY=`date '+%d-%b-%Y:%H:%M'`; export TODAY

echo "Going to clean the Alert log for "$ORACLE_SID" on $HOSTNAME"

/usr/bin/cp $LOG_DIR/alert_$ORACLE_SID.log $LOG_DIR/alert_$ORACLE_SID.log.$TODAY
/usr/bin/cat /dev/null > $LOG_DIR/alert_$ORACLE_SID.log
/usr/bin/touch $LOG_DIR/alert_$ORACLE_SID.log
/usr/bin/compress $LOG_DIR/alert_$ORACLE_SID.log.$TODAY

echo "Done Cleaning the Alert Log"
#eof

Reader Feedback

Joe T. writes: When cleaning out the alert log, I would rather keep at least the last 24-48 hours of messages to avoid having to go back and spend unnecessary time uncompressing the old alert log when dealing with a problem.

For More Information

  • Feedback: E-mail the editor with your thoughts about this tip.
  • More tips: Hundreds of free Oracle tips and scripts.
  • Tip contest: Have an Oracle tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize -- submit your tip today!
  • Ask the Experts: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.
  • Forums: Ask your technical Oracle questions--or help out your peers by answering them--in our active forums.
  • Best Web Links: Oracle tips, tutorials, and scripts from around the Web.

This was first published in June 2003

Dig deeper on Oracle database design and architecture

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close