Shell script to purge diagnostic files using ADRCI utility

 Using following shell script we can easily purge diagnostic files such as trace, alert, cdump etc.

$ vi /home/oracle/adrci_purge.sh

#!/usr/bin/ksh

#

#

#

# Description

# Shell script to  purge ADR contents using ADRCI utility.

#

###

 

LOCKFILE=/tmp/adrci_purge_.lck

 

###

 

######

# Start Of Functions

#

# tidyup . common fuction called if error has occured

tidyup () {

        rm -f ${LOCKFILE}

        echo "ERROR: Purge aborted at `date` with exit code ${ERR}"

        exit ${ERR}

}

 

######

# End Of Functions

 

### Main Program

 

# Check user is oracle

USERID=`/usr/bin/id -u -nr`

if [ $? -ne 0 ]

then

        echo "ERROR: unable to determine uid"

        exit 99

fi

#if [ "${USERID}" != "oracle" ]

#then

#        echo "ERROR: This script must be run as oracle"

#        exit 98

#fi

 

echo "INFO: Purge started at `date`"

 

# Check if lockfile exists

if [ -f ${LOCKFILE} ]

then

        echo "ERROR: Lock file already exists"

        echo "       Purge already active or incorrectly terminated"

        echo "       If you are sure tidy isn.t active, please remove "

        echo "       ${LOCKFILE}"

            #rm -f ${LOCKFILE}

        exit 97

fi

 

# Create lock file

touch ${LOCKFILE} 2>/dev/null

if [ $? -ne 0 ]

then

        echo "ERROR: Unable to create lock file"

        exit 96

fi

 

# Purge ADR contents

 

echo "INFO: adrci purge started at `date`"

 

 

ALL_DATABASES=`cat /etc/oratab|grep -v "^#"|  grep -Eo '^[^ ]+' |cut -f1 -d: -s`

 

for DB in $ALL_DATABASES

do

   unset  TWO_TASK

   export ORACLE_SID=$DB

   export ORACLE_HOME=`grep "^${DB}:" /etc/oratab|cut -d: -f2 -s`

   export PATH=$ORACLE_HOME/bin:$PATH

   echo "---> Database $ORACLE_SID, using home $ORACLE_HOME"

 

  $ORACLE_HOME/bin/adrci exec="set base /u01/oracle;show homes"|grep -v : | while read file_line

  do

  echo "INFO: adrci purging diagnostic destination " $file_line

 

  echo "INFO: purging ALERT older than 60 days .."

  $ORACLE_HOME/bin/adrci exec="set base /u01/oracle;set homepath $file_line;purge -age 43200 -type ALERT"

 

  echo "INFO: purging INCIDENT older than 60 days .."

  $ORACLE_HOME/bin/adrci exec="set base /u01/oracle;set homepath $file_line;purge -age 43200 -type INCIDENT"

 

  echo "INFO: purging TRACE older than 60 days .."

  $ORACLE_HOME/bin/adrci exec="set base /u01/oracle;set homepath $file_line;purge -age 43200 -type TRACE"

 

  echo "INFO: purging CDUMP older than 60 days .."

  $ORACLE_HOME/bin/adrci exec="set base /u01/oracle;set homepath $file_line;purge -age 43200 -type CDUMP"

 

  echo "INFO: purging HM older than 60 days .."

  $ORACLE_HOME/bin/adrci exec="set base /u01/oracle;set homepath $file_line;purge -age 43200 -type HM"

 

  echo ""

  echo ""

 

done

 

done

 

 

# All completed

rm -f ${LOCKFILE}

echo "SUCC: Purge completed successfully at `date`"

exit 0



# crontab -e

0 1 * * * /orabackup/scripts/adrci_purge.sh


1 comment: