Hi, everyone.

Please find below a shell script that can be used as “housekeeper” of the Oracle log files:

  • ALERT
  • INCIDENT
  • TRACE
  • CDUMP
 
If you want to understand a bit more, please have a look at the Oracle Doc: “adrci“.
 
  • adrci_housekeeper_v1.sh:

==============================================

#!/bin/bash

ORACLE_BASE=/opt/oracle
ORACLE_HOME=/opt/oracle/product/12.1.0.2/db
TIME=1440

ORA_BASE_DIAG=${ORACLE_BASE}/diag/rdbms

DB_NR=`ls -ld ${ORA_BASE_DIAG}/* | wc -l`

x=1

while [ ${x} -le ${DB_NR} ]; do

ORA_BASE_DIAG_DIR=`ls -ld $ORA_BASE_DIAG/* | awk ‘ORS=”;” {print $9}’ | cut -d ‘;’ -f${x} | sed “s|${ORACLE_BASE}/||g”`

echo -e “set homepath ${ORA_BASE_DIAG_DIR}; purge -age ${TIME} -type ALERT” | $ORACLE_HOME/bin/adrci
echo -e “set homepath ${ORA_BASE_DIAG_DIR}; purge -age ${TIME} -type CDUMP” | $ORACLE_HOME/bin/adrci
echo -e “set homepath ${ORA_BASE_DIAG_DIR}; purge -age ${TIME} -type TRACE” | $ORACLE_HOME/bin/adrci
echo -e “set homepath ${ORA_BASE_DIAG_DIR}; purge -age ${TIME} -type INCIDENT” | $ORACLE_HOME/bin/adrci

x=$((x+1))

done

==============================================

  •  chmod +x adrci_housekeeper_v1.sh
e.g:

./adrci_housekeeper_v1.sh

PS: Just adapt ORACLE_BASE, ORACLE_HOME and TIME variables to your need.
${TIME} = Time to keep the logs in minutes: 60*24 = 1440 minutes (1 Day).

If there is more than one ORACLE_HOME in the database server, you can use the script below.

  • adrci_housekeeper_v2.sh: 

==============================================

#!/bin/bash

ORACLE_BASE=$1
ORACLE_HOME=$2
TIME=$3
ORA_BASE_DIAG=${ORACLE_BASE}/diag/rdbms


if [ -z “${ORACLE_BASE}” ] || [ -z “$ORACLE_HOME” ]; then

echo “Missing mandatory parameter(s): [ORACLE_BASE] or [ORACLE_HOME].”
echo “Please try again with the right values.”

exit;

fi

DB_NR=`ls -ld ${ORA_BASE_DIAG}/* | wc -l`

x=1

while [ ${x} -lt ${DB_NR} ]; do

ORA_BASE_DIAG_DIR=`ls -ld $ORA_BASE_DIAG/* | awk ‘ORS=”;” {print $9}’ | cut -d ‘;’ -f${x} | sed “s|${ORACLE_BASE}/||g”`

echo -e “set homepath ${ORA_BASE_DIAG_DIR}; purge -age ${TIME} -type ALERT” | $ORACLE_HOME/bin/adrci
echo -e “set homepath ${ORA_BASE_DIAG_DIR}; purge -age ${TIME} -type CDUMP” | $ORACLE_HOME/bin/adrci
echo -e “set homepath ${ORA_BASE_DIAG_DIR}; purge -age ${TIME} -type TRACE” | $ORACLE_HOME/bin/adrci
echo -e “set homepath ${ORA_BASE_DIAG_DIR}; purge -age ${TIME} -type INCIDENT” | $ORACLE_HOME/bin/adrci

x=$((x+1))

done

==============================================

  •  chmod +x adrci_housekeeper_v2.sh
This second script requires three parameters: [ORACLE_BASE], [ORACLE_HOME] and [TIME].
e.g:
./adrci_housekeeper_v2.sh /opt/oracle /opt/oracle/product/12.1.0.2/db 1440

PS: ${TIME} = Time to keep the logs in minutes: 60*24 = 1440 minutes (1 Day).

Feel free to: use, adapt or change.

See you in the next post.