你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux 下Oracle 开机自启动 与 oratab, dbstart 脚本 说明

[日期:2012-04-14] 来源:Linux社区  作者:tianlesoftware [字体:大 中 小]

2.2 dbshut 脚本

  1. gg1:/u01/app/Oracle/product/11.2.0.3/db_1/bin>cat dbshut  
  2. #!/bin/sh  
  3. #  
  4. # $Id: dbshut.sh 22-may-2008.05:19:31arogers Exp $  
  5. # Copyright (c) 1991, 2008, Oracle. Allrights reserved.   
  6. #  
  7.    
  8. ###################################  
  9. #  
  10. # usage: dbshut $ORACLE_HOME  
  11. #  
  12. # This script is used to shutdown ORACLEfrom /etc/rc(.local).  
  13. # It should ONLY be executed as part of thesystem boot procedure.  
  14. #  
  15. # This script will shutdown all databaseslisted in the oratab file  
  16. # whose third field is a "Y" or"W".  If the third field is setto "Y" and  
  17. # there is no ORACLE_SID for an entry (thefirst field is a *),  
  18. # then this script will ignore that entry.  
  19. #  
  20. # This script requires that ASMORACLE_SID's start with a +, and  
  21. # that non-ASM instance ORACLE_SID's do notstart with a +.  
  22. #  
  23. # Note:  
  24. # Use ORACLE_TRACE=T for tracing this script.  
  25. # Oracle Net Listener is also shutdownusing this script.  
  26. #  
  27. # The progress log for each instanceshutdown is logged in file  
  28. # $ORACLE_HOME/shutdown.log.  
  29. #  
  30. # On all UNIX platforms except SOLARIS  
  31. # ORATAB=/etc/oratab  
  32. #  
  33. # To configure, update ORATAB withInstances that need to be shutdown  
  34. #   Entries are of the form:  
  35. #   $ORACLE_SID:$ORACLE_HOME:<N|Y>:  
  36. #   An example entry:  
  37. #   main:/usr/lib/oracle/emagent_10g:Y  
  38. #  
  39. #####################################  
  40.    
  41. trap 'exit' 1 2 3  
  42. case $ORACLE_TRACE in  
  43.   T) set-x ;;  
  44. esac  
  45.    
  46. # Set path if path not set (if called from/etc/rc)  
  47. SAVE_PATH=/bin:/usr/bin:/etc:${PATH} ;export PATH  
  48. SAVE_LLP=$LD_LIBRARY_PATH  
  49.    
  50. # The this to bring down Oracle Net Listener  
  51. ORACLE_HOME_LISTNER=$1  
  52. if [ ! $ORACLE_HOME_LISTNER ] ; then  
  53.   echo"ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle NetListener"  
  54.  echo "Usage: $0 ORACLE_HOME"  
  55. else  
  56.  LOG=$ORACLE_HOME_LISTNER/listener.log  
  57.    
  58.   #Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to  
  59.   # adifferent ORACLE_HOME for each entry in the oratab.  
  60.  export ORACLE_HOME=$ORACLE_HOME_LISTNER  
  61.    
  62.   #Stop Oracle Net Listener  
  63.   if[ -f $ORACLE_HOME_LISTNER/bin/tnslsnr ] ; then  
  64.    echo "$0: Stoping Oracle Net Listener" >> $LOG2>&1  
  65.    $ORACLE_HOME_LISTNER/bin/lsnrctl stop >> $LOG 2>&1 &  
  66.  else  
  67.    echo "Failed to auto-stop Oracle Net Listener using$ORACLE_HOME_LISTNER/bin/tnslsnr"  
  68.   fi  
  69. fi  
  70.    
  71. # Set this in accordance with the platform  
  72. ORATAB=/etc/oratab  
  73. if [ ! $ORATAB ] ; then  
  74.  echo "$ORATAB not found"  
  75.  exit 1;  
  76. fi  
  77.    
  78. # Stops an instance  
  79. stopinst() {  
  80.  ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`  
  81.   if[ "$ORACLE_SID" = '*' ] ; then  
  82.    ORACLE_SID=""  
  83.   fi  
  84. # Called programs use same database ID  
  85.  export ORACLE_SID  
  86.  ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`  
  87. # Called scripts use same home directory  
  88.  export ORACLE_HOME  
  89. # Put $ORACLE_HOME/bin into PATH andexport.  
  90.  PATH=$ORACLE_HOME/bin:${SAVE_PATH} ; export PATH  
  91. # add for bug 652997  
  92.  LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${SAVE_LLP} ; export LD_LIBRARY_PATH  
  93.  PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora  
  94.    
  95. # See if it is a V6 or V7 database  
  96.  VERSION=undef  
  97.   if[ -f $ORACLE_HOME/bin/sqldba ] ; then  
  98.    SQLDBA=sqldba  
  99.    VERSION=`$ORACLE_HOME/bin/sqldba command=exit | awk '  
  100.      /SQL\*DBA: (Release|Version)/ {split($3, V, ".") ;  
  101.      print V[1]}'`  
  102.    case $VERSION in  
  103.      "6") ;;  
  104.      *) VERSION="internal" ;;  
  105.    esac  
  106.  else  
  107.    if [ -f $ORACLE_HOME/bin/svrmgrl ] ; then  
  108.      SQLDBA=svrmgrl  
  109.      VERSION="internal"  
  110.    else  
  111.      SQLDBA="sqlplus /nolog"  
  112.     fi  
  113.   fi  
  114.    
  115.  case $VERSION in  
  116.    "6")  sqldbacommand=shutdown ;;  
  117.    "internal")  $SQLDBA<<EOF  
  118. connect internal  
  119. shutdown immediate  
  120. EOF  
  121.     ;;  
  122.     *)  $SQLDBA <<EOF  
  123. connect / as sysdba  
  124. shutdown immediate  
  125. quit  
  126. EOF  
  127.     ;;  
  128.  esac  
  129.    
  130.   iftest $? -eq 0 ; then  
  131.    echo "${INST} \"${ORACLE_SID}\" shut down."  
  132.  else  
  133.    echo "${INST} \"${ORACLE_SID}\" not shut down."  
  134.   fi  
  135. }  
  136.    
  137. #  
  138. # Loop for every entry in oratab file andand try to shut down  
  139. # that ORACLE  
  140. #  
  141. # Following loop shuts down 'DatabaseInstance[s]' with 'Y' entry  
  142.    
  143. cat $ORATAB | while read LINE  
  144. do  
  145.  case $LINE in  
  146.  \#*)                ;;        #comment-line in oratab  
  147.   *)  
  148.  ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`  
  149.   if[ "$ORACLE_SID" = '*' ] ; then  
  150.      # NULL SID - ignore  
  151.      ORACLE_SID=""  
  152.      continue  
  153.   fi  
  154.   #Proceed only if last field is 'Y' or 'W'  
  155.   if[ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then  
  156.    if [ `echo $ORACLE_SID | cut -b 1` != '+' ]; then  
  157.      INST="Database instance"  
  158.      ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`  
  159.      LOG=$ORACLE_HOME/shutdown.log  
  160.      echo "Processing $INST \"$ORACLE_SID\": log file$LOG"  
  161.      stopinst >> $LOG 2>&1  
  162.    fi  
  163.   fi  
  164.   ;;  
  165.  esac  
  166. done  
  167.    
  168. #  
  169. # Following loop shuts down 'DatabaseInstance[s]' with 'W' entry  
  170. #  
  171. cat $ORATAB | while read LINE  
  172. do  
  173.  case $LINE in  
  174.  \#*)                ;;        #comment-line in oratab  
  175.   *)  
  176.  ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`  
  177.   if[ "$ORACLE_SID" = '*' ] ; then  
  178.      # NULL SID - ignore  
  179.      ORACLE_SID=""  
  180.      continue  
  181.   fi  
  182.   #Proceed only if last field is 'Y' or 'W'  
  183.   if[ "`echo $LINE | awk -F: '{print $NF}' -`" = "W" ] ; then  
  184.    if [ `echo $ORACLE_SID | cut -b 1` != '+' ]; then  
  185.      INST="Database instance"  
  186.      ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`  
  187.      LOG=$ORACLE_HOME/shutdown.log  
  188.      echo "Processing $INST \"$ORACLE_SID\": log file$LOG"  
  189.      stopinst >> $LOG 2>&1  
  190.    fi  
  191.   fi  
  192.   ;;  
  193.  esac  
  194. done  
  195.    
  196. #  
  197. # Following loop shuts down 'ASMInstance[s]'  
  198. #  
  199.    
  200. cat $ORATAB | while read LINE  
  201. do  
  202.   case$LINE in  
  203.    \#*)                ;;        #comment-line in oratab  
  204.    *)  
  205.    ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`  
  206.    if [ "$ORACLE_SID" = '*' ] ; then  
  207.      # NULL SID - ignore  
  208.      ORACLE_SID=""  
  209.      continue  
  210.    fi  
  211.     #Proceed only if last field is 'Y'.  
  212.     #Entries whose last field is not Y or N are not DB entry, ignore them.  
  213.    if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y"] ; then  
  214.      if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then  
  215.        INST="ASM instance"  
  216.        ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`  
  217.        LOG=$ORACLE_HOME/shutdown.log  
  218.        echo "Processing $INST \"$ORACLE_SID\": log file$LOG"  
  219.        stopinst >> $LOG 2>&1  
  220.      fi  
  221.    fi  
  222.   ;;  
  223.  esac  
  224. done  
  225. gg1:/u01/app/oracle/product/11.2.0.3/db_1/bin>  

通过以上信息,我们可以看出,我们只需要修改/etc/oratab脚本就可以了,dbstart 和dbshut命令可以从/etc/oratab里获取需要的参数值。

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款