Shell实现的Oracle启动脚本分享
程序员文章站
2022-06-07 22:51:16
usage: sh oracled [start|stop|restart] sids 其中sids是数据库名,多个名称之间用逗号分隔。缺省的操作是 restart ,也可...
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}