当前位置: 移动技术网 > 网络运营>服务器>Linux > Shell实现的Oracle启动脚本分享

Shell实现的Oracle启动脚本分享

2017年12月12日  | 移动技术网网络运营  | 我要评论

usage: sh oracled [start|stop|restart] sids 其中sids是数据库名,多个名称之间用逗号分隔。缺省的操作是 restart ,也可以指定需要进行的操作( start | stop | restart )

复制代码 代码如下:

#!/bin/sh 
 
cmdname="restart" 
# get oracle sid information from env by default. 
oraclesid=${oracle_sid} 
env_oraclesid=${oracle_sid} 
 
function echohelp(){ 
  echo "******oracled tool helper******" 
  echo "usage:sh oracled [start|stop|restart] sids" 
  echo "sids : seperated by comma" 
  exit 5 

 
function startoracle(){ 
  echo "begin to start oracle ..." 
 
  lsnrctl start 
  for cursid in `echo ${oraclesid} | awk 'begin {rs=","}{ors="\n"}{print $1}'` ; do 
    if [ "x${cursid}" = "x" ] ; then 
      continue; 
    fi 
    export oracle_sid=${cursid} 
 
sqlplus /nolog <<eof 
 
connect /as sysdba 
startup 
exit 
exit 
 
eof 
 
    echo "oracle db [${cursid}] started ok." 
  done 

function stoporacle(){ 
  echo "begin to stop oracle ..." 
 
  for cursid in `echo ${oraclesid} | awk 'begin {rs=","}{ors="\n"}{print $1}'` ; do 
    if [ "x${cursid}" = "x" ] ; then 
      continue; 
    fi 
    export oracle_sid=${cursid} 
 
sqlplus /nolog <<eof 
 
connect /as sysdba 
shutdown immediate 
exit 
exit 
 
eof 
 
    echo "oracle db [${cursid}] stopped ok." 
  done 
  lsnrctl stop 

function restartoracle(){ 
  stoporacle 
  startoracle 

 
 
if [ $# -lt 1 ] ; then 
  echohelp 
fi 
 
until [ $# -eq 0 ] 
do 
  tmpvorg=$1 
  tmpv=`echo "${tmpvorg}" | awk '{printf "%s",$1}' | tr '[a-z]' '[a-z]'` 
  if [ $tmpv = "start" -o $tmpv = "restart" -o $tmpv = "stop" ] ; then 
    cmdname=${tmpv} 
  elif [ $tmpv = "--help" -o $tmpv = "-h" ] ; then 
    echohelp 
  else 
    oraclesid=$tmpvorg 
  fi 
 
  shift 
done 
 
if [ "x${cmdname}" = "x" ] ; then 
  echohelp 
fi 
 
${cmdname}oracle 
 
export oracle_sid=${env_oraclesid} 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网