Tuesday, 17 March 2020

alertlog rotation script, cleanup trace location for oracle database


Below script will delete the trc,trm,backup alertlog zip files and alert xml files for all databases in one server.

#!/bin/bash
DB_LIST=`egrep -i ":Y|:N" /etc/oratab | cut -d":" -f1 | grep -v "\#" | grep -v "\*"`
for i in $DB_LIST ; do
export ORACLE_SID=$i
export ORACLE_HOME=`egrep -i ":Y|:N" /etc/oratab |grep $ORACLE_SID| cut -d":" -f2 | grep -v "\#" | grep -v "\*"`
export PATH=$ORACLE_HOME/bin:$PATH
TRACE_LOC=`sqlplus -s "/ as sysdba" <<EOF
       set heading off feedback off verify off
       select VALUE from v\\$diag_info where NAME='Diag Trace';
       exit
EOF`
##deleting trc,trm and .gz files in trace location
find $TRACE_LOC -name '*.trc' -mtime +5 -exec rm -f {} \;
find $TRACE_LOC -name '*.trm' -mtime +5 -exec rm -f {} \;
find $TRACE_LOC -name '*.gz' -mtime +10 -exec rm -f {} \;
TO_DATE="`date '+%d%m%Y%H%M%S'`";
##rotate alertlog.
mv $TRACE_LOC/alert_$ORACLE_SID.log $TRACE_LOC/alert_$ORACLE_SID.$TO_DATE
touch $TRACE_LOC/alert_$ORACLE_SID.log
chmod 640 $TRACE_LOC/alert_$ORACLE_SID.log
gzip $TRACE_LOC/alert_$ORACLE_SID.$TO_DATE
ALXML_LOC=`sqlplus -s "/ as sysdba" <<EOF
       set heading off feedback off verify off
       select VALUE from v\\$diag_info where NAME='Diag Alert';
       exit
EOF`
##deleting alert xml files
find $ALXML_LOC -name 'log_*' -mtime +5 -exec rm -f {} \;
done

No comments:

Post a Comment