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


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 >

    Requires Free Membership to View

$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

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.