Shell Script: Trace FIle Management


#-----------------------------------------------------------------------------
# Script Name  : TRACE_LOG_MGMT_V1.0.sh
# Author       : Adithya Sirimalla
# Support      : adithya_dba@yahoo.com
# Version      : V1.0
# Oracle       : 11g,10g,9i,8i
# Description  : Used to delete Old Trace files(BDUMP,CDUMP,UDUMP,ADUMP), and zeriong alert,listener logfiles
#
# Usage        : TRACE_LOG_MGMT.sh [-I <INSTANCE_NAME> [-T <NUMBER_OF_DAYS_TO_RETAIN>] [-AL <YES/NO>] ] [ -L <YES/NO> ]
#
#                Where:
#                  -I  : Instance Name should be followed for which trace file management is required (Instance Name is required for Trace file and Alert Log).
#                  -T  : Number of Days trace file you want to keep on in BDUMP,CDUMP,UDUMP,ADUMP or 11g Diag location, and previous months trace files sill be deleted"
#   -AL : Y/N(Yes or No Value) .To perform Alert Log Zeroing or not (Default: NO)
#   -L  : Y/N(Yes or No Value) .To perform Alert Log Zeroing or not (Default: NO)
# TRACE_LOG_MGMT.sh -I BAN5PLSG -T 18 -AL Y -L Y > /db/app/oracle/T_L_M_`date +"%a_%b_%d_%Y-%H_%M_%S"`.log &
# Revision History: At end of script.
#-----------------------------------------------------------------------------
#!/bin/bash
# Default minimum PATH
PATH=/usr/bin:/bin
export PATH
case `uname` in
  HP-UX )
PATH=/usr/bin:/usr/ccs/bin:/usr/contrib/bin:/opt/nettladm/bin:/opt/pd/bin:/usr/bin/X11:/usr/contrib/bin/X11:/opt/upgrade/bin:/opt/hparray/bin:/opt/perf/bin:/usr/sbin:/opt/atok/bin:/opt/asx/bin/X11:/opt/egb/bin:/opt/vje/bin:/opt/resmon/bin:/opt/pred/bin:/opt/ignite/bin:/opt/OV/bin/OpC:bin:/opt/prm/bin:/opt/hpnpl//bin:/opt/networker/bin:/usr/local/bin:/opt/FAXclient/bin:/usr/robelle/bin:/usr/local/bin/:/usr/local/bin:$PATH
;;
SunOS)
PATH=/usr/ccs/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/ucb:/etc:/users/rapidigm:$PATH
;;
AIX)
PATH=/usr/vac/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java131/jre/bin:/usr/java131/bin:/usr/local/bin:/opt/FAXclient/bin:/usr/robelle/bin:/usr/local/bin/:/usr/local/bin:$PATH
;;
Liunx)
PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin:$PATH
;;
esac
export PATH
if [ -r /var/opt/oracle/oratab ]            #Checking oratab file
then
ORATAB=/var/opt/oracle/oratab
elif [ -r /etc/oratab ]
then
ORATAB=/etc/oratab
else
echo "Oracle Not Installed or Not Configured, ORATAB file not found!"
exit 0
fi
####################################################################################################################
#################                      Start of Function Definitions               #################################
####################################################################################################################
#-----------------------------------------------------------------------------
# Function   : ShowUsage
# Description: Print usage syntax.
#-----------------------------------------------------------------------------
ShowUsage()
{
echo "USAGE: TRACE_LOG_MGMT.sh -I <INSTANCE_NAME> [-T <NUMBER_OF_DAYS_TO_RETAIN>] [-AL <YES/NO>] [ -LL <YES/NO>]"
        echo "Where:"
        echo "   -I  : Instance Name should be followed for which trace file management is required (Instance Name is required for Trace file and Alert Log)."
echo "           (Default: FileMgmt will Not Applied )"
echo "   -T   :Number of Days trace file you want to keep on in BDUMP,CDUMP,UDUMP,ADUMP or 11g DIAG location, and previous months trace files sill be deleted"
        echo "   -AL : Y/N(Yes or No Value) .To perform Alert Log Zeroing or not (Default: NO)."
echo "   -L  : Y/N(Yes or No Value) .To perform Listener Log Zeroing or not (Default: NO)."
echo "************************************************************************"
        return


} # End of ShowUsage
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Function   : DelBdFCmd10g
# Description: Deletes .trc files from BDUMP Location.
#-----------------------------------------------------------------------------
DelBdFCmd10g()
{
if [ -w "$BdD" ]
then
cd $BdumpDir
BdTrcFList=`find . -name "*.trc" -mtime +$TrcRtnDys -print |xargs ls -l| awk {'print $9'}`
for BVal in ${BdTrcLFist}
do
#echo "$BVal"
#cp -p "$BVal" /dump/DBA/trace/
rm "$BVal"
done
echo "*******************************************************************************"
echo "*******Done:::Trace Files in $BdumpDir are Successfully Deleted****************"
echo "*******************************************************************************"
else
echo "*************************************************************************"
echo "Error:::Bdump Directory : $BdumpDir is Write Proected : Can not Execute Script"
echo "*************************************************************************"
exit 0
fi
        return
} # End of DelBdFCmd
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Function   : DelUdFCmd10g
# Description: Deletes .trc files from UDUMP Location.
#-----------------------------------------------------------------------------
DelUdFCmd10g()
{
if [ -w "$UdD" ]
then
cd $UdumpDir
UdTrcFList=`find . -name "*.trc" -mtime +$TrcRtnDys -print |xargs ls -l| awk {'print $9'}`
for UVal in ${UdTrcFList}
do
#echo "$UVal"
#cp -p "$UVal" /dump/DBA/trace/
rm "$UVal"
done
echo "*******************************************************************************"
echo "*******Done:::Trace Files in $UdumpDir are Successfully Deleted****************"
echo "*******************************************************************************"
else
echo "*************************************************************************"
echo "Error:::Udump Directory : $UdumpDir is Write Proected : Can not Execute Script"
echo "*************************************************************************"
exit 0
fi
        return
} # End of DelUdFCmd
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Function   : DelCdFCmd10g
# Description: Deletes .trc files from CDUMP Location.
#-----------------------------------------------------------------------------
DelCdFCmd10g()
{
if [ -w "$CdD" ]
then
cd $CdumpDir
CdTrcFList=`find . -name "core_*" -mtime +$TrcRtnDys`
for CVal in ${CdTrcFList}
do
#echo "$CVal"
#cp -rp "$CVal" /dump/DBA/trace/
rm -r "$CVal"
done
echo "*******************************************************************************"
echo "*******Done:::Trace Files in $CdumpDir are Successfully Deleted****************"
echo "*******************************************************************************"
else
echo "*************************************************************************"
echo "Error:::Cdump Directory : $CdumpDir is Write Proected : Can not Execute Script"
echo "*************************************************************************"
exit 0
fi
        return
} # End of DelCdFCmd
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Function   : DelAdFCmd10g
# Description: Deletes .aud files from ADUMP Location.
#-----------------------------------------------------------------------------
DelAdFCmd10g()
{
if [ -w "$AdD" ]
then
cd $AdumpDir
AdTrcFList=`find . -name "*.aud" -mtime +$TrcRtnDys -print |xargs ls -l| awk {'print $9'}`
for AVal in ${AdTrcFList}
do
#echo "$AVal"
#cp -p "$AVal" /dump/DBA/trace/
rm "$AVal"
done
echo "*******************************************************************************"
echo "*******Done:::Trace Files in $AdumpDir are Successfully Deleted****************"
echo "*******************************************************************************"
else
echo "*************************************************************************"
echo "Error:::Adump Directory : $AdumpDir is Write Proected : Can not Execute Script"
echo "*************************************************************************"
exit 0
fi
        return
} # End of DelAdFCmd
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Function   : AlertClrCmd10g
# Description: Clears Alert Logfile after backup.
#-----------------------------------------------------------------------------
AlertClrCmd10g()
{
if [ -w "$BdD" ]
then
cd $BdumpDir
cp alert_$InstanceName.log alert_$InstanceName.log.bkp.`date +"%a_%b_%d_%Y-%H_%M_%S"`
cat /dev/null > alert_$InstanceName.log
echo "*************************************************************************"
echo "Done::: alert_$InstanceName.log Backup is performed and null is insurted"
echo "*************************************************************************"
else
echo "*************************************************************************"
echo "Error:::Bdump Directory : $BdumpDir is Write Proected : Can not Execute Script"
echo "*************************************************************************"
exit 0
fi
return
} # End of AlertClrCmd
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Function   : RunTasks10g
# Description: Created a Script file which internall calls respective trace file management scripts
#-----------------------------------------------------------------------------
RunTasks10g()
{
if [ $TrcFilDel = "Y" ]
then
#echo $BdumpDir
DelBdFCmd10g
DelUdFCmd10g
DelCdFCmd10g
DelAdFCmd10g
fi
if [ $AlertLogClr = "Y" ]
then
#echo $BdumpDir
AlertClrCmd10g
fi
        return

} # End of RunTasks
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Function   : BkpTrcFil11g
# Description: Clears Alert Logfile after backup.
#-----------------------------------------------------------------------------
BkpTrcFil11g()
{
AdrBkpdate=`date +"%Y%m%d%H%M%S"`
AdrBkpDir=/dump/DBA/trace
cd /dump/DBA/trace
if [ -d "$AdrBkpDir"/"$InstanceName" ]
then
echo "*******"
else
#echo "$AdrBkpDir"/"$InstanceName Dir Creating"
mkdir "$InstanceName"
fi
cd $DigDst
if [ -w `pwd` ]
then
AdrHome=`adrci exec="show homes" |grep -v "ADR Homes:"`
export ADR_BASE=`adrci exec="show base" |awk -F\" '{print $2}'`
#echo $AdrHome
echo "set home $AdrHome;set autoshell on;cd $ADR_BASE/$AdrHome; begin backup;cp -R metadata $AdrBkpDir/$InstanceName/metadata_${AdrStem}_${AdrBkpdate}_backup;end backup"
adrci exec="set home $AdrHome;set autoshell on;cd $ADR_BASE/$AdrHome; begin backup;cp -R metadata $AdrBkpDir/$InstanceName/metadata_${AdrBkpdate}_backup;end backup"
adrci exec="set home $AdrHome;set autoshell on;cd $ADR_BASE/$AdrHome; begin backup;cp -R alert $AdrBkpDir/$InstanceName/alert_${AdrBkpdate}_backup;end backup"
adrci exec="set home $AdrHome;set autoshell on;cd $ADR_BASE/$AdrHome; begin backup;cp -R cdump $AdrBkpDir/$InstanceName/cdump_${AdrBkpdate}_backup;end backup"
adrci exec="set home $AdrHome;set autoshell on;cd $ADR_BASE/$AdrHome; begin backup;cp -R hm $AdrBkpDir/$InstanceName/hm_${AdrBkpdate}_backup;end backup"
adrci exec="set home $AdrHome;set autoshell on;cd $ADR_BASE/$AdrHome; begin backup;cp -R incident $AdrBkpDir/$InstanceName/incident_${AdrBkpdate}_backup;end backup"
adrci exec="set home $AdrHome;set autoshell on;cd $ADR_BASE/$AdrHome; begin backup;cp -R incpkg $AdrBkpDir/$InstanceName/incpkg_${AdrBkpdate}_backup;end backup"
adrci exec="set home $AdrHome;set autoshell on;cd $ADR_BASE/$AdrHome; begin backup;cp -R ir $AdrBkpDir/$InstanceName/ir_${AdrBkpdate}_backup;end backup"
adrci exec="set home $AdrHome;set autoshell on;cd $ADR_BASE/$AdrHome; begin backup;cp -R lck $AdrBkpDir/$InstanceName/metadata_${AdrBkpdate}_backup;end backup"
adrci exec="set home $AdrHome;set autoshell on;cd $ADR_BASE/$AdrHome; begin backup;cp -R metadata_dgif $AdrBkpDir/$InstanceName/metadata_dgif_${AdrBkpdate}_backup;end backup"
adrci exec="set home $AdrHome;set autoshell on;cd $ADR_BASE/$AdrHome; begin backup;cp -R metadata_pv $AdrBkpDir/$InstanceName/metadata_pv_${AdrBkpdate}_backup;end backup"
adrci exec="set home $AdrHome;set autoshell on;cd $ADR_BASE/$AdrHome; begin backup;cp -R stage $AdrBkpDir/$InstanceName/stage_${AdrBkpdate}_backup;end backup"
adrci exec="set home $AdrHome;set autoshell on;cd $ADR_BASE/$AdrHome; begin backup;cp -R sweep $AdrBkpDir/$InstanceNamer/sweep_${AdrBkpdate}_backup;end backup"
adrci exec="set home $AdrHome;set autoshell on;cd $ADR_BASE/$AdrHome; begin backup;cp -R trace $AdrBkpDir/$InstanceName/trace_${AdrBkpdate}_backup;end backup"
echo "**********************************************************"
echo "**************Done:ADR Backup Completed*******************"
echo "**********************************************************"
fi
return
} # End of AlertClrCmd
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Function   : AlertClrCmd11g
# Description: Clears Alert Logfile after backup.
#-----------------------------------------------------------------------------
AlertClrCmd11g()
{
cd $DigDst
AdrHome=`adrci exec="show homes" |grep -v "ADR Homes:"`
cd $DigDst/$AdrHome/trace
if [ -w `pwd` ]
then

cp alert_$InstanceName.log alert_$InstanceName.log.bkp.`date +"%a_%b_%d_%Y-%H_%M_%S"`
cat /dev/null > alert_$InstanceName.log
echo "**********************************************************"
echo "**************Done:ALert Log Purged Successfully**********"
echo "**********************************************************"
else
echo "*************************************************************************"
echo "Error:::Bdump Directory : $DigDst/$AdrHome/trace is Write Proected : Can not Execute Script"
echo "*************************************************************************"
exit 0
fi
return
} # End of AlertClrCmd
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Function   : RunTasks11g
# Description: Created a Script file which internall calls respective trace file management scripts
#-----------------------------------------------------------------------------
RunTasks11g()
{
if [ $TrcFilDel = "Y" ]
then
#BkpTrcFil11g
TrcRtnMins=$(($TrcRtnDys*1440))
#echo $TrcRtnMins
cd $DigDst
#echo $DigDst
AdrHome=`adrci exec="show homes" |grep -v "ADR Homes:"`
#echo "set home $AdrHome;purge -age $TrcRtnMins -type ALERT"
adrci exec="set home $AdrHome;purge -age $TrcRtnMins -type ALERT"
  adrci exec="set home $AdrHome;purge -age $TrcRtnMins -type INCIDENT"
  adrci exec="set home $AdrHome;purge -age $TrcRtnMins -type TRACE"
adrci exec="set home $AdrHome;purge -age $TrcRtnMins -type CDUMP"
adrci exec="set home $AdrHome;purge -age $TrcRtnMins -type HM"
adrci exec="set home $AdrHome;purge -age $TrcRtnMins -type UTSCDMP"
echo "**********************************************************"
echo "***Done:purged Trace Files older than $TrcRtnDys days*****"
echo "**********************************************************"
fi
if [ $AlertLogClr = "Y" ]
then
AlertClrCmd11g
fi
        return

} # End of RunTasks
#-----------------------------------------------------------------------------



####################################################################################################################
#################                      End of Function Definitions                 #################################
####################################################################################################################
####################################################################################################################
#################                      Start of Reading Script Arguments           #################################
####################################################################################################################
CountI=0
CountT=0
CountAL=0
CountL=0
if [ ${#} -eq 8 ]
then
case $1 in
'-I' )
OptionI=$1
CountI=`expr ${CountI} + 1`
InstanceName=$2
;;
'-T' )
OptionT=$1
CountT=`expr ${CountT} + 1`
TrcFilDel="Y"
TrcRtnDys=$2
;;
'-AL' )  
OptionAL=$1
CountAL=`expr ${CountAL} + 1`
AlertLogClr=$2
;;
'-L' )
OptionL=$1
CountL=`expr ${CountL} + 1`
LisLogClr=$2
;;
* )
echo "*******************************************************************************"
echo "Error:::Invalid Options $1 in the Command Line: Can Not Perform Trace File Mgmt"
echo "*******************************************************************************"
ShowUsage
exit 0
;;
esac
case $3 in
'-I' )
OptionI=$3
CountI=`expr ${CountI} + 1`
InstanceName=$4
;;
'-T' )
OptionT=$3
CountT=`expr ${CountT} + 1`
TrcFilDel="Y"
TrcRtnDys=$4
;;
'-AL' )  
OptionAL=$3
CountAL=`expr ${CountAL} + 1`
AlertLogClr=$4
;;
'-L' )
OptionL=$3
CountL=`expr ${CountL} + 1`
LisLogClr=$4
;;
* )
echo "*******************************************************************************"
echo "Error:::Invalid Options $3 in the Command Line: Can Not Perform Trace File Mgmt"
echo "*******************************************************************************"
ShowUsage
exit 0
;;
esac
case $5 in
'-I' )
OptionI=$5
CountI=`expr ${CountI} + 1`
InstanceName=$6
;;
'-T' )
OptionT=$5
CountT=`expr ${CountT} + 1`
TrcFilDel="Y"
TrcRtnDys=$6
;;
'-AL' )  
OptionAL=$5
CountAL=`expr ${CountAL} + 1`
AlertLogClr=$6
;;
'-L' )
OptionL=$5
CountL=`expr ${CountL} + 1`
LisLogClr=$6
;;
* )
echo "*******************************************************************************"
echo "Error:::Invalid Options $5 in the Command Line: Can Not Perform Trace File Mgmt"
echo "*******************************************************************************"
ShowUsage
exit 0
;;
esac
case $7 in
'-I' )
OptionI=$7
CountI=`expr ${CountI} + 1`
InstanceName=$8
;;
'-T' )
OptionT=$7
CountT=`expr ${CountT} + 1`
TrcFilDel="Y"
TrcRtnDys=$8
;;
'-AL' )  
OptionAL=$7
CountAL=`expr ${CountAL} + 1`
AlertLogClr=$8
;;
'-L' )
OptionL=$7
CountL=`expr ${CountL} + 1`
LisLogClr=$8
;;
* )
echo "*******************************************************************************"
echo "Error:::Invalid Options $7 in the Command Line: Can Not Perform Trace File Mgmt"
echo "*******************************************************************************"
ShowUsage
exit 0
;;
esac
elif [ ${#} -eq 6 ]
then
case $1 in
'-I' )
OptionI=$1
CountI=`expr ${CountI} + 1`
InstanceName=$2
;;
'-T' )
OptionT=$1
CountT=`expr ${CountT} + 1`
TrcFilDel="Y"
TrcRtnDys=$2
;;
'-AL' )  
OptionAL=$1
CountAL=`expr ${CountAL} + 1`
AlertLogClr=$2
;;
'-L' )
OptionL=$1
CountL=`expr ${CountL} + 1`
LisLogClr=$2
;;
* )
echo "*******************************************************************************"
echo "Error:::Invalid Options $1 in the Command Line: Can Not Perform Trace File Mgmt"
echo "*******************************************************************************"
ShowUsage
exit 0
;;
esac
case $3 in
'-I' )
OptionI=$3
CountI=`expr ${CountI} + 1`
InstanceName=$4
;;
'-T' )
OptionT=$3
CountT=`expr ${CountT} + 1`
TrcFilDel="Y"
TrcRtnDys=$4
;;
'-AL' )  
OptionAL=$3
CountAL=`expr ${CountAL} + 1`
AlertLogClr=$4
;;
'-L' )
OptionL=$3
CountL=`expr ${CountL} + 1`
LisLogClr=$4
;;
* )
echo "*******************************************************************************"
echo "Error:::Invalid Options $3 in the Command Line: Can Not Perform Trace File Mgmt"
echo "*******************************************************************************"
ShowUsage
exit 0
;;
esac
case $5 in
'-I' )
OptionI=$5
CountI=`expr ${CountI} + 1`
InstanceName=$6
;;
'-T' )
OptionT=$5
CountT=`expr ${CountT} + 1`
TrcFilDel="Y"
TrcRtnDys=$6
;;
'-AL' )  
OptionAL=$5
CountAL=`expr ${CountAL} + 1`
AlertLogClr=$6
;;
'-L' )
OptionL=$5
CountL=`expr ${CountL} + 1`
LisLogClr=$6
;;
* )
echo "*******************************************************************************"
echo "Error:::Invalid Options $5 in the Command Line: Can Not Perform Trace File Mgmt"
echo "*******************************************************************************"
ShowUsage
exit 0
;;
esac
elif [ ${#} -eq 4 ]
then
case $1 in
'-I' )
OptionI=$1
CountI=`expr ${CountI} + 1`
InstanceName=$2
;;
'-T' )
OptionT=$1
CountT=`expr ${CountT} + 1`
TrcFilDel="Y"
TrcRtnDys=$2
;;
'-AL' )  
OptionAL=$1
CountAL=`expr ${CountAL} + 1`
AlertLogClr=$2
;;
'-L' )
OptionL=$1
CountL=`expr ${CountL} + 1`
LisLogClr=$2
;;
* )
echo "*******************************************************************************"
echo "Error:::Invalid Options $1 in the Command Line: Can Not Perform Trace File Mgmt"
echo "*******************************************************************************"
ShowUsage
exit 0
;;
esac
case $3 in
'-I' )
OptionI=$3
CountI=`expr ${CountI} + 1`
InstanceName=$4
;;
'-T' )
OptionT=$3
CountT=`expr ${CountT} + 1`
TrcFilDel="Y"
TrcRtnDys=$4
;;
'-AL' )  
OptionAL=$3
CountAL=`expr ${CountAL} + 1`
AlertLogClr=$4
;;
'-L' )
OptionL=$3
CountL=`expr ${CountL} + 1`
LisLogClr=$4
;;
* )
echo "*******************************************************************************"
echo "Error:::Invalid Options $3 in the Command Line: Can Not Perform Trace File Mgmt"
echo "*******************************************************************************"
ShowUsage
exit 0
;;
esac
elif [ ${#} -eq 2 ]
then
case $1 in
'-I' )
OptionI=$1
CountI=`expr ${CountI} + 1`
InstanceName=$2
;;
'-T' )
OptionT=$1
CountT=`expr ${CountT} + 1`
TrcFilDel="Y"
TrcRtnDys=$2
;;
'-AL' )  
OptionAL=$1
CountAL=`expr ${CountAL} + 1`
AlertLogClr=$2
;;
'-L' )
OptionL=$1
CountL=`expr ${CountL} + 1`
LisLogClr=$2
;;
* )
echo "*******************************************************************************"
echo "Error:::Invalid Options $1 in the Command Line: Can Not Perform Trace File Mgmt"
echo "*******************************************************************************"
ShowUsage
exit 0
;;
esac
else
echo "**************************************************************************"
echo ":::::::::::::::::::::::::::: H  E  L  P ::::::::::::::::::::::::::::::::::"
echo "**************************************************************************"
ShowUsage
exit 0
fi


if [ $CountI -eq 0 -a $CountT -eq 1 ]
then
echo "************************************************************************************************************"
echo "Error:::Mandatory Options -I (Instance Name) Not Found in the Command Line: Can Not Perform Trace File Mgmt"
echo "************************************************************************************************************"
ShowUsage
exit 0
elif [ $CountI -eq 0 -a $CountAL -eq 1 ]
then
echo "************************************************************************************************************"
echo "Error:::Mandatory Options -I (Instance Name) Not Found in the Command Line: Can Not Perform Trace File Mgmt"
echo "************************************************************************************************************"
ShowUsage
exit 0
elif [ $CountI -gt 1 -o $CountT -gt 1 -o $CountAL -gt 1 -o $CountL -gt 1 ]
then
echo "*************************************************************************************"
echo "Error:::Duplicate Options Found in the Command Line: Can Not Perform Trace File Mgmt"
echo "*************************************************************************************"
ShowUsage
exit 0
elif [ $CountT -eq 0 -a $CountAL -eq 0 -a $CountL -eq 0 ]
then
echo "*************************************************************************************************************"
echo "Error:::Any one of -T, -AL or -L Options are Not Found in the Command Line: Can Not Perform Trace File Mgmt"
echo "*************************************************************************************************************"
ShowUsage
exit 0
elif [ $CountI -eq 1 -a $CountL -eq 1 -a $CountT -eq 0 -a $CountAL -eq 0 ]
then
echo "*************************************************************************************************************"
echo "Warning:::-I (Instance Name) Not required for Listener FIle Management::::Continuing with Listener Log Mgmt::"
echo "*************************************************************************************************************"
#ShowUsage
CountI=0
#echo $CountI
else
if [ $CountT -eq 0 ]
then
TrcFilDel="N"
fi
if [ $CountAL -eq 0 ]
then
AlertLogClr="N"
fi
if [ $CountL -eq 0 ]
then
LisLogClr="N"
fi
fi

if [ "$InstanceName" = "agent" -o "$InstanceName" = "920" -o "$InstanceName" = "1020" -o "$InstanceName" = "10202" -o "$InstanceName" = "806" -o "$InstanceName" = "817" -o "$InstanceName" = "734" -o "$InstanceName" = "8174" -o "$InstanceName" = "901" -o "$InstanceName" = "9201"  ]
then
echo "*********************************************************************************"
echo "Error:::No Database Available with $InstanceName: Can Not Perform Trace File Mgmt"
echo "*********************************************************************************"
exit 0
fi
if [ $CountT -eq 1 ]
then
case $TrcRtnDys in
( +([0-9]) )  
InTPramsAcpt="Y"
  ;;
 *)  
InTParamAcpt="N"
echo "*********************************************************************************"
echo "Error:::Please Pass Valid Number for Option -T"
echo "*********************************************************************************"
ShowUsage
exit 0
;;
esac
fi
if [ $CountAL -eq 1 ]
then
case $AlertLogClr in
       'Y')  
InAPramsAcpt="Y"
  ;;
'N')  
InAPramsAcpt="Y"
  ;;
 *)  
InAParamAcpt="N"
echo "*********************************************************************************"
echo "Error:::Please Pass Y or N for Option -AL"
echo "*********************************************************************************"
ShowUsage
exit 0
;;
esac
fi
if [ $CountL -eq 1 ]
then
case $LisLogClr in
       'Y')  
InLPramsAcpt="Y"
  ;;
'N')  
InLPramsAcpt="Y"
  ;;
 *)  
InLParamAcpt="N"
echo "*********************************************************************************"
echo "Error:::Please Pass Y or N for Option -L"
echo "*********************************************************************************"
ShowUsage
exit 0
;;
esac
fi

##########################################################################################################################
#######################          End of Reading Script Arguments                 #########################################
##########################################################################################################################
case `uname` in
SunOS)
ID="/usr/xpg4/bin/id -nu"
;;
*)
ID="/usr/bin/id -nu"
;;
esac
InstMch=0
if [ $CountI -eq 1 ]
then
#ID="/usr/xpg4/bin/id -nu"
ValueList=`grep -i "^[a-z,0-9]" "$ORATAB" | sed -e 's/ //g'`               #Reading the ORATAB entries
InstanceCnt=0
for Value in ${ValueList}
do
InstanceCnt=`expr ${InstanceCnt} + 1`                              #Reading the ORATAB entries
       IsName="`echo ${Value} | cut -d: -f1`"
        IsHome="`echo ${Value} | cut -d: -f2`"
       IsAuto="`echo ${Value} | cut -d: -f3 | tr '[:lower:]' '[:upper:]'`"
        IsOwner=`ls -lLd ${IHome}/bin 2>/dev/null | awk '{print $3}'`
if [ "$IsName" = "$InstanceName" ]
then
IName="`echo ${Value} | cut -d: -f1`"
        IHome="`echo ${Value} | cut -d: -f2`"
       IAuto="`echo ${Value} | cut -d: -f3 | tr '[:lower:]' '[:upper:]'`"
        IOwner=`ls -lLd ${IHome}/bin 2>/dev/null | awk '{print $3}'`
ROwner=`${ID}`
InstMch=`expr ${InstMch} + 1`
fi
done
if [ "$InstMch" -eq 1 ]
then
if [ "$IName" = "$InstanceName" ]
        then
if [ $ROwner = $IOwner ]
               then
                ORACLE_SID="$InstanceName"
                    export ORACLE_SID
OraSid="${IName}"
       ORACLE_HOME="$IHome"
        export ORACLE_HOME
                PATH="$IHome"/bin:$PATH
                        export PATH
ProcCount=0
       Procs=`ps -fe 2>/dev/null | cut -c1-132 | sed -e 's/ *$//' | grep -v grep | \
        egrep "ora_pmo._${OraSid}\$|ora_dbw._${OraSid}\$|ora_lgw._${OraSid}\$|ora_smo._${OraSid}"'$'`
for Proc in pmo dbw lgw smo
              do
                      Result=`echo ${Procs} | grep "ora_${Proc}._${OraSid}" 2>&1`
                       if [ -n "${Result}" ]
                    then
                        ProcCount=`expr ${ProcCount} + 1`
                      fi
        done
if [ ${ProcCount} -ge 4 ]
       then
OVP="v\$parameter2"
Status=`echo 'set heading off
set timing off
                      set time off
                        select status from v$instance;
                        exit' | sqlplus -s "/ as sysdba"`
DbName=`echo 'set heading off
set timing off
                       set time off
                        select name from v$database;
       exit' | sqlplus -s "/ as sysdba"`
DVersion=`echo 'set heading off
set timing off
                      set time off
                        select VERSION from v$instance;
                        exit' | sqlplus -s "/ as sysdba"`
St="`echo ${Status} | cut -d: -f1`"
Dn="`echo ${DbName} | cut -d: -f1`"
Dv="`echo ${DVersion} | cut -d: -f1`"
       else
        Status="Down"
DbName="Unknown"
DVersion="Unknown"
                        St="Down"
Dn="Unknown"
Dv="Unknown"
                fi
if [ $St = "OPEN" ]
then
Is1098ver=0
if [[ $Dv = 10.* ]]
then
Is1098ver=1
elif [[ $Dv = 9.* ]]
then
Is1098ver=1
elif [[ $Dv = 8.* ]]
then
Is1098ver=1
fi
if [ $Is1098ver -eq 1 ]
then
      BdumpDir=`sqlplus -s / <<EOD
set echo off
set termout off
set feedback off
set heading off
select value from $OVP where name='background_dump_dest';
EOD`
CdumpDir=`sqlplus -s / <<EOD
set echo off
set termout off
set feedback off
set heading off
select value from $OVP where name='core_dump_dest';
EOD`
UdumpDir=`sqlplus -s / <<EOD
set echo off
set termout off
set feedback off
set heading off
select value from $OVP where name='user_dump_dest';
EOD`
AdumpDir="$ORACLE_HOME"/rdbms/audit
#echo "$BdumpDir"
#echo "$AdumpDir"
#echo "$UdumpDir"
#echo "$AdumpDir"
BdD="`echo ${BdumpDir} | cut -d: -f1`"
CdD="`echo ${CdumpDir} | cut -d: -f1`"
UdD="`echo ${UdumpDir} | cut -d: -f1`"
AdD="`echo ${AdumpDir} | cut -d: -f1`"
RunTasks10g
#echo "********Done*****"
#fi
elif [[ $Dv = 11.* ]]
then
DigDst=`sqlplus -s / <<EOD
set echo off
set termout off
set feedback off
set heading off
select value from $OVP where NAME='diagnostic_dest';
EOD`
#echo "$DigDst"
Dd="`echo ${DigDst} | cut -d: -f1`"
#echo $Dd
RunTasks11g
#echo "********Done*****"
else
echo "*************************************************************************"
echo "Error::::::::::::::::Unsupported Database Version::::::::::::::::::::::::"
echo "*************************************************************************"
fi
else
echo "*************************************************************************"
echo "Error::::::::::::::::Database $InstanceName is Not Available:::::::::::::"
echo "*************************************************************************"
#exit 0
fi
                else
echo "*************************************************************************"
echo "Error:::Not Othorized to execute as $ROwner. Please Log on to $IOwner::::"
echo "*************************************************************************"
exit 0
fi              #End Of If Condition user logged in Database owner or not
fi  #Checking Instance Name
fi #Checking Instance match

if [ "$InstanceCnt" -ge 0 -a "$InstMch" -eq 0 ]
then
echo "*****************************************************************************************"
echo "Error::::No Instance Configured with $InstanceName,Invalid Instance Name at Command Line"
echo "*****************************************************************************************"
#exit 0
fi
fi
if [ $LisLogClr = "Y" ]
then
LisHom=`grep ":/" /etc/oratab | grep -v "*"  | sed 1q | awk -F: '{print $2}'`
LisOwn=`grep ":/" /etc/oratab | grep -v "*"  | sed 1q | awk -F: '{print $7}'`
EOwner=`${ID}`
if [ $EOwner != $LisOwn ]
        then
echo "*************************************************************************"
echo "Error:::Not Othorized to execute as $EOwner. Please Log on to $LisOwn::::"
echo "*************************************************************************"
exit 0
fi
LisVer=`$LisHom/bin/lsnrctl status |grep TNSLSNR|sed -e 's/ //g'|cut -c48-53`
#echo $LisVer
IsL1098ver=0
if [[ $LisVer = 10.* ]]
then
IsL1098ver=1
elif [[ $LisVer = 9.* ]]
then
IsL1098ver=1
elif [[ $LisVer = 8.* ]]
then
IsL1098ver=1
fi
if [[ $LisVer = 11.* ]]
then
LisLFil=`$LisHom/bin/lsnrctl status|sed -e 's/ //g'|grep ListenerLogFile|cut -c16-500|sed 's/alert/trace/g'|sed 's/log.xml/listener.log/g'`
echo $LisLFil
if [ -w $LisLFil ]
then
#echo $LisLFil
cp $LisLFil $LisLFil.bkp.`date +"%a_%b_%d_%Y-%H_%M_%S"`
#cat /dev/null > Listener.log
else
echo "*************************************************************************"
echo "Error::: $LisLFil is Write Proected : Can not Execute Script"
echo "*************************************************************************"
exit 0
fi
elif [ $IsL1098ver -eq 1 ]
then
LisLFil=`$LisHom/bin/lsnrctl status|sed -e 's/ //g'|grep ListenerLogFile|cut -c16-500`
if [ -w $LisLFil ]
then
#echo $LisLFil
cp $LisLFil $LisLFil.bkp.`date +"%a_%b_%d_%Y-%H_%M_%S"`
#cat /dev/null > Listener.log
else
echo "*************************************************************************"
echo "Error::: $LisLFil is Write Proected : Can not Execute Script"
echo "*************************************************************************"
exit 0
fi
else
echo "*************************************************************************"
echo "Error::::::::::::::::Unsupported Listener Version::::::::::::::::::::::::"
echo "*************************************************************************"
fi
fi

#-----------------------------------------------------------------------------
# Revision History
#-----------------------------------------------------------------------------
# Revision History 1:
# Author          : Adithya
# Version 1(Beta) : 27th June 2012
# Support         :adithya_dba@yahoo.com
# Testing OS      : AIX
# Testing Database: Oracle 10g,11g
# Script Status   : Initial Script (Version 1)
# Changes         : No Changes
#----------------------------------------------------------------------------

1 comment:

  1. Hi admin, Congratulations I was looking for something like that and found it here. I'm really grateful for your blog post. You will find a lot of approaches after visiting your post.
    Document Management Software
    Electronic Document Management System
    Document Management System
    Cloud Document Management Software

    ReplyDelete