Sunday, June 2, 2019

resize alert log for each database using script.

This script automatcally back's up exisitng alert log to a location you need(BKP_ALT_DIR)  and resize the alert log to 0.



code of the script:


COMMAND=$0
PGM=${COMMAND##*/}
DATE=$(date "+%Y%m%d")
hostname=`hostname -s`
PWD=`pwd`
repdir=$PWD
LOG=$repdir/logs

################ Change Retention Here ###########

BKP_ALT_DIR=/backup/2_week/$hostname/ALERT_BKP

############ 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:

  for db in `cat /etc/oratab| egrep -v '(^#|\+|\-)'|cut -f1 -d: -s|egrep -v 'OMS'|egrep -v 'AGENT'`
       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=/opt/oracle/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
                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 /opt/oracle/diag/rdbms/$l_db/$db_check/trace/alert_$db_check.log |grep -v tail |wc -l` != 0 ];
                           then
                         echo "`lsof | grep /opt/oracle/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 "completed:" >>$LOG/DB_up_list.log


Hope this helps......

PostgreSql: Useful Commands-

 1)   ************************* Users ***************************  -- List of users with roles assigned: SELECT usename AS role_name,   CASE...