首页 > 代码库 > shell 2 解析

shell 2 解析

 

 

---- shell 3



/home/oracle/utility/macro/call_autopurge_arch.sh

 Description: Call purge archive log file job
# Syntax: autopurge_arch.sh [Oracle_SID] [archived base dir] [#hours kept]
#
SCRIPT_DIR=/home/oracle/utility/macro
#${SCRIPT_DIR}/autopurge_archlog.sh nGende /ngdedb 6

#add in 20160901
${SCRIPT_DIR}/autopurge_archlog.sh oasprod /oasprod  24

|
more ${SCRIPT_DIR}/autopurge_archlog.sh
#!/usr/bin/sh
#
# Description: Purging archive log files stored in archive log mount point ${DB_BASE_DIR}log
#
#
# Syntax: autopurge_archlog.sh [Oracle_SID] [archived base dir] [#days kept]
#
#
PATH=/usr/local/bin:/usr/bin:$PATH
echo "------------------------------------------------------------------------"
SCRIPT_DIR=/home/oracle/utility/macro
up_flag=`${SCRIPT_DIR}/chkdbup.sh ${1}`
       #echo $dbname" " $up_flag
       if [ ${up_flag} -eq 0 ]; then

                export ORACLE_SID=$1
                export ORAENV_ASK=NO
                . oraenv >/dev/null
                export ORAENV_ASK=

                DB_BASE_DIR=$2;export DB_BASE_DIR
                KEEP_HOURS=$3; export KEEP_HOURS

                PURGE_ARCH=/home/oracle/utility/macro/purge_file.sh; export PURGE_ARCH

                ARCH_DIR="${DB_BASE_DIR}log ";  export ARCH_DIR
                sqlplus -s "/ as sysdba" @${SCRIPT_DIR}/get_define_arclog.sql ${KEEP_HOURS}
                ARCH_LOG_PATTERN=`sed -e ‘s/ //g‘ /tmp/get_define_arclog.lst|tail -n 1 `.gz;
                export ARCH_LOG_PATTERN;
                if [ -f ${ARCH_LOG_PATTERN} ]
                  then
                    echo "define archive log had gzip"
                  else
                    ARCH_LOG_PATTERN=`sed -e ‘s/ //g‘ /tmp/get_define_arclog.lst|tail -n 1 `
                    if [ -f ${ARCH_LOG_PATTERN} ]
                      then
                        echo "define archive log don‘t gzip"
                      else
                        echo "not need house keeping"
                        exit 0
                    fi
                fi
                echo ${ARCH_DIR} ${ARCH_LOG_PATTERN}
               find ${ARCH_DIR} ! -newer  ${ARCH_LOG_PATTERN}  -exec  ${PURGE_ARCH} {} \;
        else
                echo "`date`: Instance ${1} not running on `hostname` ..."
  fi
 

|  
more /home/oracle/utility/macro/purge_file.sh
#!/usr/bin/sh
echo "Purging $1 ..."

|
more ${SCRIPT_DIR}/get_define_arclog.sql
set echo off heading off veri off feedback off
spool /tmp/get_define_arclog.lst
select trim(name) from v$archived_log where first_time = (select max(first_time) from v$archived_log
 where first_time < (sysdate - &1/24))
/
spool off
exit    


--shell 4

vi /home/oracle/utility/macro/alert_master.sh
"/home/oracle/utility/macro/alert_master.sh" 23 lines, 451 characters
#!/bin/ksh
#Program : alert_master.sh
#Author : david
#Document : This is the main program,checks alert for all instances
#


#SCRIPTLOC=/cluster/dhp/oracle/erp_scripts/alert_scripts

SCRIPTLOC=/home/oracle/utility/macro

export SCRIPTLOC

for i in `cat /etc/oratab |grep -v "^[#]"|cut -d: -f1`
do
  ora_stat=`ps -ef|grep -v grep|grep ora_smon_$i|wc -l`
  ora_chk=`expr $ora_stat`
  if [ $ora_chk -eq 1 ]
  then
    $SCRIPTLOC/alert.sh $i
  fi
done

|
more  alert.sh

#!/bin/ksh
#Program : alert.sh
#Author : david
#Document : This is the sub-program called by alert_master.sh
#Purpose : Send E-Mail notification,if there is an ORA- error in Alert Log
#
SCRIPTDIR=/home/oracle/utility/macro
ORACLE_SID=$1
export ORACLE_SID
if [ -z "$1" ]
  then
  echo "Usage: alert.sh "
  exit 99
fi
stat=`ps -ef|grep -v grep|grep ora_smon_$1|wc -l`
ora_stat=`expr $stat`
if [ $ora_stat -eq 0 ]
  then
  exit 0
fi
ORACLE_HOME=`cat /etc/oratab|grep -v "^[#]"|grep $ORACLE_SID|cut -d: -f2`
export ORACLE_HOME
export PATH=$ORACLE_HOME/bin:$PATH

$ORACLE_HOME/bin/sqlplus -s ‘/ as sysdba‘ << !
  @/home/oracle/utility/macro/get_dict_parm
  exit
!
ALRT_CHK=`cat /home/oracle/utility/macro/alert_$1_dir.log|grep ?|wc -l`
alrt_stat=`expr $ALRT_CHK`
if [ $alrt_stat -eq 1 ]
  then
    ALERT_DIR=$ORACLE_HOME/rdbms/log
  else
    ALERT_DIR=`cat /home/oracle/utility/macro/alert_$1_dir.log`
fi
export ALERT_DIR
cd $SCRIPTDIR


if [ -f $SCRIPTDIR/cntfile_$1.log ]
  then
    chk=`cat $SCRIPTDIR/cntfile_$1.log|wc -l`
    chk1=`expr $chk`
    if [ $chk1 -gt 0 ]
      then
        cat $SCRIPTDIR/cntfile_$1.log|read num
      else
        num=0
    fi
  else
    touch $SCRIPTDIR/cntfile_$1.log
    num=0
fi
if [ $num -gt 0 ]
  then
    cd $ALERT_DIR
    cat alert_${ORACLE_SID}.log |wc -l |read ct1
    sz=`expr $ct1 - $num`
    if [ $sz -eq 0 ]
      then
        exit
    fi
cd $ALERT_DIR
cat alert_${ORACLE_SID}.log |tail -$sz|grep ORA- |\
grep -v ORA-279|\
grep -v ORA-000060|\
grep -v ORA-00060|\
grep -v 308|\
grep -v 3217|\
cat > /tmp/alerterr_$1.log 2>$SCRIPTDIR/error_$1_.log
ora_cnt=`cat /tmp/alerterr_$1.log|wc -l`
ora_num=`expr $ora_cnt`

if [ $ora_num -gt 0 ]
  then
    cat /tmp/alerterr_$1.log|/usr/bin/mailx -s "Alert Log Errors for the database $ORACLE_SID" ts-dba@test.com.cn
fi
    cat alert_${ORACLE_SID}.log |wc -l|read cnt
    echo $cnt > $SCRIPTDIR/cntfile_$1.log
    exit
  else
    cd $ALERT_DIR
    cat alert_${ORACLE_SID}.log | grep ORA- |cat > /tmp/alerterr_$1.log
    ora_cnt=`cat /tmp/alerterr_$1.log|wc -l`
    ora_num=`expr $ora_cnt`
    if [ $ora_num -gt 0 ]
      then
      cat /tmp/alerterr_$1.log|/usr/bin/mailx -s "Alert Log Errors for the database $ORACLE_SID" ts-dba@test.com.cn
    fi
    cat alert_${ORACLE_SID}.log | wc -l |read cnt
    echo $cnt > $SCRIPTDIR/cntfile_$1.log
fi

---    shell 5

/home/oracle/utility/macro/purge_trc_files.sh

#!/bin/ksh
#
# Description: Purge useless files
# Syntax: purge_trc_files.sh
#
# Date: 22-JUL-2003
#

dt=`date ‘+%y%m%d%H%M‘`


export PATH=$PATH:/usr/local/bin
export ROOT_DIR=/home/oracle
export SCRIPT_DIR=$ROOT_DIR/utility/macro
export LOGFILE_DIR=$ROOT_DIR/utility/log
export TMP_DIR=$ROOT_DIR/utility/tmp

LOGFILE=$LOGFILE_DIR/purge_trc_files.log

DBLIST=${SCRIPT_DIR}/pfdblist

export ORACLE_SID=xprprod
export ORAENV_ASK=NO
. oraenv >/dev/null
export ORAENV_ASK=

echo "****** "`date` >> $LOGFILE
grep -v ‘^#‘ $DBLIST | awk ‘{ print $1 }‘ | sort -u | while read dbname
do
        # 1. check whether db is up and running on server
        up_flag=`${SCRIPT_DIR}/chkdbup.sh ${dbname}`
      # echo $dbname" " $up_flag
        if [ ${up_flag} -eq 0 ]; then


                echo "Starting Purging Files for ${dbname}"`date`"\n" >> $LOGFILE

                # 2. Purge FIles

                grep -v ‘^#‘ $DBLIST | grep -i ${dbname} | while read dbname pfdir pfext pf_retention
                do
                        find $pfdir -name \*.trc -mtime +${pf_retention} -exec ls -lrt {} \; 1>> ${LOGFILE}
                        find $pfdir -name \*.trc -mtime +${pf_retention} -exec rm {} \; 1>> ${LOGFILE} 2>&1
                        find $pfdir -name \*.trm -mtime +${pf_retention} -exec ls -lrt {} \; 1>> ${LOGFILE}
                        find $pfdir -name \*.trm -mtime +${pf_retention} -exec rm {} \; 1>> ${LOGFILE} 2>&1
                        find $pfdir -name \*.aud -mtime +${pf_retention} -exec ls -lrt {} \; 1>> ${LOGFILE}
                        find $pfdir -name \*.aud -mtime +${pf_retention} -exec rm {} \; 1>> ${LOGFILE} 2>&1
                        find $pfdir -name \*_arc\*.trc -mtime +${pf_retention} -exec rm {} \; 1>> ${LOGFILE} 2>&1
                done
        fi
done
echo "****** Completed at : "`date`"\n" >> $LOGFILE


|

more ${SCRIPT_DIR}/pfdblist

# DB list for purging files

bizprod   /bizlinkdb/adump   .aud 2
bizprod   /bizlinkdb/diag/rdbms/bizprod/bizprod/trace  .trc 2
bizprod   /bizlinkdb/diag/rdbms/bizprod/bizprod/trace  .trm 2
centrprod /centrproddb/diag/rdbms/centrprod/centrprod/trace .trc 4
centrprod /centrproddb/diag/rdbms/centrprod/centrprod/trace .trm 4
centrprod /centrproddb/adump .aud 2
~

----shell 6~
~more /home/oracle/utility/blocker/detect_blocker.sh
echo_usage()
{
        echo "Usage : `basename $0` [SID] <sleep time>"
        echo $*
        echo "Cause: no SID or Database is not running on server"
        exit 0
}

if [ $# -lt 2 ]
then
        echo_usage
fi

#
# See whether the DB is actually running on this machine or not
#

export ORACLE_SID=$1
ps -ef | grep -v grep | grep ora_smon_${ORACLE_SID} > /dev/null
if [ $? -ne 0 ]
then
        echo_usage
fi

export PATH=$PATH:/usr/local/bin
export ORAENV_ASK=NO

. oraenv >/dev/null
export ORAENV_ASK=

export ROOT_DIR=/home/oracle
export SCRIPT_DIR=$ROOT_DIR/utility/blocker
export LOGFILE_DIR=$ROOT_DIR/utility/log
export TMP_DIR=$ROOT_DIR/utility/tmp

EXT="`date ‘+%y%m%d%H%M%S‘`"

FILE1=/tmp/detect_blocker1.${ORACLE_SID}.$EXT
FILE2=/tmp/detect_blocker2.${ORACLE_SID}.$EXT

OPCMsgCmd=/opt/OV/bin/OpC/opcmsg  


SLEEPTIME=$2

${SCRIPT_DIR}/check_blocker  $ORACLE_SID | grep -v ‘DO NOT KILL‘ | grep KILL > $FILE1;
sleep $SLEEPTIME;
${SCRIPT_DIR}/check_blocker  $ORACLE_SID | grep -v ‘DO NOT KILL‘ | grep KILL > $FILE2;

while read LINE; do
COMPSTR=`echo $LINE | awk ‘{print $2}‘`
if [ `grep $COMPSTR $FILE2 | wc -l` -eq 1 ]; then
   echo ‘Blocker detected as : ‘;
   echo
   echo ‘Oracle Session ID/Serial#      : ‘ $COMPSTR
   OVOMSG=‘DB :‘${ORACLE_SID}‘-Blocker Detected Oracle Session ID/Serial#      : ‘${COMPSTR}‘, Please keep monitoring system and donnot kill the blocker until warning messages is
exceeding at least 3 times with the same blocker.‘
   echo $OVOMSG
   $OPCMsgCmd s=critical a=db  o=blocker  msg_grp=db  msg_t="${OVOMSG}"
fi;
done < $FILE1

shell 2 解析