Mani's Blog

March 15, 2011

>How to rotate alert log with retention

Filed under: Oracle — mani @ 10:30 pm
Tags: , ,

>Following script maintains alert 14 days, if you run the script once a day.  Generally I run it from cron

00 08 * * * /local/home/oracle/bin/rotate_alert.sh /local/opt/oracle/diag/rdbms/xnodb02b/XNODB02B1/trace/alert_XNODB02B1.log 14 > /dev/null 2>&1

#!/bin/sh

logfile=${1}
retention=${2:-14}

current=$retention
prev=`expr $current – 1`

while [ ${current} -gt 0 ]
do
if [ -f ${logfile}.${prev} ]
then
mv ${logfile}.$prev ${logfile}.$current
fi
current=`expr $current – 1`
prev=`expr $current – 1`
done

mv $logfile ${logfile}.0
touch $logfile

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: