Edit the lines once copied to the editor.
******************************** Script **********************
#!/bin/ksh
# ***********--------------------------------------------------************#
# *********** Script name : #
# *********** Author : Siva B #
# *********** Usage : To backup alert log and re-size to 0. #
# *********** Date : #
# #
# *********** Version Change History #
# #
# #
# ***********--------------------------------------------------************#
# *********** Define variables:
# OS variables:
COMMAND=$0
PGM=${COMMAND##*/}
DATE=$(date "+%Y%m%d")
hostname=`hostname -s`
PWD=/opt/siva/alert_test
repdir=$PWD
LOG=$repdir/logs
################ Change Retention Here ###########
ORACLE_BASE=/opt/app/oracle
BKP_ALT_DIR=/opt/siva/alert # to save the alert log file in some other mount/disk.
DB_NAME=TEST_DB # Disable this incase if you want to run for all DB's on this host and enable below.
############ Done ########################
# Log directory checks:
if [ ! -d ${LOG} ]
then
mkdir -p $LOG
else
rm $LOG/*log
fi
if [ ! -d ${BKP_ALT_DIR} ]
then
mkdir -p $BKP_ALT_DIR
fi
# copying alert log files to desired folder:
# enable below line if you want to backup alert log file and reset for all db's on this host.
# for db in `cat /etc/oratab| egrep -v '(^#|\+|\-)'|cut -f1 -d: -s|egrep -v 'OMS'|egrep -v 'AGENT'`
for db in `echo $DB_NAME`
do
db_check=`pgrep -al pmon|grep $db |cut -f3,4 -d_`
if [ -n "$db_check" ]
then
echo $db
db_sid=$db_check
l_db=`echo $db | tr [A-Z] [a-z]`
alert_dir=$ORACLE_BASE/diag/rdbms/$l_db/$db_check/trace
cd $alert_dir
echo $alert_dir
echo "$BKP_ALT_DIR"
cp alert_$db_check.log $BKP_ALT_DIR/alert_"$db_check"_$DATE.log
gzip $BKP_ALT_DIR/alert_"$db_check"_$DATE.log
echo "alert_$db_check.log copy is done for $db" >>$LOG/DB_up_list.log
ready=0
while [ $ready -eq 0 ]
do
if [ `lsof | grep $ORACLE_BASE/diag/rdbms/$l_db/$db_check/trace/alert_$db_check.log |grep -v tail |wc -l` != 0 ];
then
echo "`lsof | grep $ORACLE_BASE/diag/rdbms/$l_db/$db_check/trace/alert_$db_check.log |grep -v tail |wc -l`"
ready=0
sleep 5
else
ready=1
fi
done
echo "resetting alert_$db_check.log for $db" >>$LOG/DB_up_list.log
> alert_$db_check.log
echo "alert_$db_check.log reset for $db is done" >>$LOG/DB_up_list.log
else
echo "$db" >>$LOG/exclude_list.log
fi
done
echo "purge older logs "
/usr/bin/find $BKP_ALT_DIR -type f -mtime +90 -exec rm {} \;
echo "completed:" >>$LOG/DB_up_list.log
No comments:
Post a Comment