maxyang2008

导航

Script to Start/Stop Oracle instance per current instance status

很多时候,都要启动虚拟机里面的测试oracle数据库,操作多了就觉得烦了,于是就写了这样一个脚本:根据当前oracle服务的状态(通过smon进程来判断),决定对oracle服务进行启动/关闭操作。

脚本中,oracle实例的名字为orcl,所以smon进程的名称就是ora_somn_orcl。
使用的时候,直接运行这个脚本即可。如果再将脚本路径加入PATH中,使用起来就更方便了 :)

#!/bin/bash

## script to start/stop oracle database according to
## current open status of oracle instance
## 2014-11-05
## yangjia


STATUS=`ps -ef |grep smon |awk '{print $8}' |head -1`
if [ "$STATUS" = "ora_smon_orcl" ]
then
lsnrctl stop
sqlplus / as sysdba <<EOF
shutdown immediate
exit
EOF
else
lsnrctl start
sqlplus / as sysdba <<EOF
startup
exit
EOF
fi

posted on 2016-07-27 23:19  Maxwell_Yang  阅读(90)  评论(0编辑  收藏  举报