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" [email protected]
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" [email protected]
    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

时间: 2024-10-05 05:58:42

shell 2 解析的相关文章

shell动态解析sql的binlog

#!/usr/bin #设置数据库连接 conn='mysql -hhost -Pport -uusername -ppassword' #获取最新的binlog文件 logfile=$($conn -e "show master logs" | tail -n 1 | awk -F" " '{print $1}') #设置a为1,用户下边的判断 a=1 #while循环 while true do #获取起始datetime fromDate=$(date &qu

shell脚本解析5----循环语句

一.for循环 for var in [ list ] do #code block done $var是循环控制变量,[list]是var需要遍历的一个集合,do/done对包含了循环体.如果do和for被写在同一行,必须在do前面加上“;”,如:for $var in [list]; do 例如: #!/bin/bash for day in Sun Mon Tue Wed Thu Fri Sat do echo $day done 执行结果: 如果列表被包含在一对括号中,则被认为是一个元素

shell脚本解析6----case语句

BASH中的case结构,可以用于进行多项分支. case "$var" in condition1) ;; condition2) ;; *) default statments;; esac 例如: #!/bin/bash echo "Hit a key, then hit return" read Keypress case "$Keypress" in [A-Z]) echo "Uppercase letter";;

shell脚本解析4----分支语句(if)

一.条件语句 1. if [expression] then #code block fi 2. if [expression] then #code block else #code block fi 3. if [expression] then #code block else if [expression]    #该处可以替换成elif [expression] then #code block else #code block fi fi 二.条件语句中常用的比较 比较操作    

shell如何解析命令行以及eval命令

1.1 shell解析命令行 shell读取和执行命令时的大致操作过程如下图: 以执行以下命令为例: echo -e "some files:" ~/i* "\nThe date:$(date +%F)\n$name's age is $((a+4))" >/tmp/a.log 假设在执行该命令前,已赋值变量"name=longshuai"和"a=24",于是重定向到/tmp/a.log中的结果为: some files

shell脚本解析9(练习3)------倒序输出

#!/bin/bash #提示用户输入 echo -n "Please enter number" read n #读入输入的值放到变量n中 sd=0 rev="" on=$n #将变量n的值保存到变量on中,方便以后用到 echo "You put number is $n" while [ $n -gt 0 ] do sd=$(($n % 10)) #求余 n =$(($n/10))     #去掉当前的最后一位数后,剩下的数 rev=&qu

shell脚本解析8(练习2)-----文件个数统计

#!/bin/bash counter=0 #变量files遍历一遍当前文件夹 for files in * do #判断files是否为文件,如果是,counter变量值加1,再赋值给自己. if [ -f "$files" ] then counter=`expr $counter + 1` fi done echo "There are $counter files in `pwd`" 执行结果: 注意:表达式counter=`expr $counter +

shell脚本解析10(练习4)------监视文件

#!/bin/bash  #判断命令行是否代带有两个文件名的参数 if [ "$1" = "" ] || [ "$2" = "" ] then      echo "Please enter file name"      exit 1 fi  #判断目标文件是否存在 if [ -e $2 ] then   echo "The file already exists"   until [

shell脚本解析3-----局部变量与函数

#!/bin/bash hello="var1" echo $hello function func1                             #定义函数func1 { local hello="var2"                    #定义内部变量hello echo $hello } func1                                          #进行函数调用 echo $hello 执行结果: 总结:局

shell脚本解析2----变量

一.一般变量 #/bin/sh num=2 echo "this is the ${num}nd"     #shell脚本语言的变量如果紧连字母时,需要加上“{}”进行区分. 输出结果: 二.系统变量 $#:传入脚本的命令行参数个数 $*:所有命令行参数值,在各个参数值之间留有空格 $0:命令本身(shell文件名) $1:第一个命令行参数 $2:第二个命令行参数 例如: #/bin/sh echo "number of vars:"$# echo "v