Script to start Oracle processes

本文介绍了一个用于启动和停止Oracle实例及其相关组件(如监听器、Enterprise Manager和iSQL*Plus)的Shell脚本。该脚本适用于Sun 10g Oracle环境,并通过检查进程ID来确认操作的成功。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/usr/bin/ksh
#
#
# set -x

##startdb.ksh

# grep process id for oracle instance and listener
orapid=`ps -ef  | grep -v grep | grep oracle | grep ora_ | grep _$ORACLE_SID | awk '{print $2}' | head -1`
lsnrpid=`ps -ef | grep -v grep | grep oracle | grep LISTENER | awk '{print $2}'  | head -1`
empid=`ps -ef  | grep -v grep | grep oracle | grep LOCAL=NO | grep oracle$ORACLE_SID  | awk '{print $2}' | head -1`
isqlpid=`ps -ef | grep -v grep | grep oracle | grep Doracle  | grep Djava.awt.headless | awk '{print $2}' | head -1` #

# start oracle instance

if [ "$orapid" -eq "" ]; then
echo "Starting Oracle instance..."
sqlplus /nolog  << !
connect /as sysdba
startup
exit
!
else
   echo "Oracle instance $ORACLE_SID is already running!"
fi


# start listener

if [ "$lsnrpid" -eq "" ]; then
   echo "Starting listener ..."
   lsnrctl start
else
   echo "Listener is already running!"
fi

# start Enterprise Manager

if [ "$empid" -eq "" ]; then
   echo "Starting Enterprise Manager ..."
   rm $ORACLE_HOME/oc4j/j2ee/oc4j_applications/applications/em/em/cabo/images/cache/*/*.gif
   emctl start dbconsole
else
   echo "Enterprise Manager is already running!"
fi

# start iSQLPLUS

if [ "$isqlpid" -eq "" ]; then
   echo "Starting iSQLPLUS ..."
   rm $ORACLE_HOME/oc4j/j2ee/oc4j_applications/applications/isqlplus/isqlplus/images/*.gif
   isqlplusctl start
else
   echo "iSQLPLUS is already running!"
fi


#
#
# check processes status
echo "/n--------------------------------"
echo "Checking Oracle processes status:"

orapid=`ps -ef | grep -v grep | grep $ORACLE_SID | awk '{print $2}' | head -1` lsnrpid=`ps -ef | grep -v grep | grep LISTENER | awk '{print $2}'`

if [ ! "$orapid" -eq "" ]; then
   echo "Oracle instance $ORACLE_SID is running!"
fi

if [ ! "$lsnrpid" -eq "" ]; then
   echo "Listener is running!"
fi

echo "--------------------------------/n"

# end

 

#!/usr/bin/ksh
# script to stop database
#
# set -x


if [ -f /export/home/oracle/product/10g/Sun10_oradb1/emctl.pid ]; then
   echo 'Stop Enterprise Manager.../n'
   emctl stop dbconsole
fi


# grep process id for oracle instance and listener

orapid=`ps -ef | grep -v grep | grep $ORACLE_SID | awk '{print $2}' | head -1` lsnrpid=`ps -ef | grep -v grep | grep LISTENER | awk '{print $2}'`


# stop oracle instance

if [ ! "$orapid" -eq "" ]; then
echo "Shutting down Oracle instance..."
sqlplus /nolog  << !
connect /as sysdba
shutdown immediate
exit
!
fi


# stop listener

if [ ! "$lsnrpid" -eq "" ]; then
   echo "Shutting down listener ..."
   lsnrctl stop
fi

 

# check processes status
echo "--------------------------------"
echo "Checking Oracle processes status:"

orapid=`ps -ef | grep -v grep | grep $ORACLE_SID | awk '{print $2}' | head -1` lsnrpid=`ps -ef | grep -v grep | grep LISTENER | awk '{print $2}'`

if [ "$orapid" -eq "" ]; then
   echo "Oracle instance $ORACLE_SID is stopped!"
fi

if [ "$lsnrpid" -eq "" ]; then
   echo "Listener is stopped!"
fi

echo "--------------------------------/n"

# end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值