dailymaint.sql

#!/bin/sh
#
#  Name:        dailymaint.sh
#
#  Desc:        Run Daily Oracle instance maintenance scripts on the given
#		Oracle instance.
#

if [ $# -lt 1 ]
then
        echo " "
        echo " Usage:  $0 <database_name> "
        echo " "
        echo " where <database_name> = name of database to run script in"
        echo " "
        exit 1
fi
 
ORACLE_SID=$1

export ORACLE_HOME=`cat /var/opt/oracle/oratab | egrep -i $ORACLE_SID | awk -F: '{print $2}'`
ORACLE_BASE=/opt/oracle;  export ORACLE_BASE
TNS_ADMIN=/usr/local/tns; export TNS_ADMIN
ORACLE_PATH=$HOME/sqltools;  export ORACLE_PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib; export LD_LIBRARY_PATH
PATH=$PATH:$ORACLE_HOME/bin; export PATH

#  retrieve the ORACLE_HOME value, from the oratab file
#  and check to make sure we got a value
 
ORACLE_HOME=`grep -i $ORACLE_SID /var/opt/oracle/oratab | awk 'BEGIN {FS=":"} {print $2}'`
 
if [ -n "$ORACLE_HOME" ]
then
        PATH=${ORACLE_HOME}/bin:${PATH}
        LD_LIBRARY_PATH=${ORACLE_HOME}/lib
 
        export ORACLE_SID ORACLE_HOME PATH LD_LIBRARY_PATH
else
        echo " "
        echo "ORACLE_SID not in oratab file ($ORACLE_SID) . . . exiting script."
        echo " "
        exit 100
fi

# Cleanup old trace files
# udump: 15 days
# cdump: 15 days
# bdump: 15 days
# adump: 30 days
DUMPDIR="/sys01/oracle/oradump"
 
find $DUMPDIR/$ORACLE_SID/udump/*.trc -mtime +15 -exec rm {} \; 2>/dev/null
find $DUMPDIR/$ORACLE_SID/cdump/*.trc -mtime +15 -exec rm {} \; 2>/dev/null
find $DUMPDIR/$ORACLE_SID/bdump/*.trc -mtime +15 -exec rm {} \; 2>/dev/null
find $DUMPDIR/$ORACLE_SID/adump/*.aud -mtime +30 -exec rm {} \; 2>/dev/null

find /opt/oracle/dbadmin/logbook/$ORACLE_SID/*.lst -mtime +6 -exec rm {} \;

# Cleanup old hotback logs
#
find /opt/oracle/dbadmin/hotback/log/$ORACLE_SID/pre_post/pre_post_log.* -mtime +10 -exec rm {} \; 2>/dev/null
find /opt/oracle/dbadmin/hotback/log/$ORACLE_SID/clog2/clog2.log.* -mtime +10 -exec rm {} \; 2>/dev/null
find /opt/oracle/dbadmin/hotback/log/$ORACLE_SID/redo_arch/*.log.* -mtime +30 -exec rm {} \; 2>/dev/null

# Run Daily Reports
cd /opt/oracle/dbadmin/logbook/$ORACLE_SID
sqlplus -s / @/opt/oracle/bin/daily.run

# Retrieve Listing of Database Links
today=`date '+%d%b'`
LINKS_FILE="${ORACLE_SID}_dlinks_${today}.lst"
LINKDIR="/data01/oradata/oralink/$ORACLE_SID"

echo "Symbolic DB links for Database:  $ORACLE_SID" > $LINKS_FILE
echo "Directory:  $LINKDIR" >> $LINKS_FILE
echo "-----------------------------------------------------" >> $LINKS_FILE
ls -l $LINKDIR   >> $LINKS_FILE

exit 0