脚本都是文本格式的,通常脚本的后缀名为.sh(windows系统下.bat)或者没有后缀名。
如果要手动执行该脚本,通常是需要当前用户为oracle用户或者有相应数据库访问权限的用户的。
你可以把你连接oracle的shell命令,同样的放到你的脚本里即可。原则上,只要你的那些命令能正常运行,那么你的脚本就能正常连接数据库了!
/etc/init.d/oracle #!/bin/sh#
# oraShell -- user start|stop script for oracle
#
LOG_EMERG=0 # system is unusable
LOG_ALERT=1 # action must be taken immediately
LOG_CRIT=2 # critical conditions
LOG_ERR=3 # error conditions
LOG_WARNING=4 # warning conditions
LOG_NOTICE=5 # normal but significant condition
LOG_INFO=6 # informational
LOG_DEBUG=7 # debug-level messages
script_name=`basename $0`
clulog()
{
log_level=$1
log_info=$2
/opt/cluster/bin/clulog -p $$ -n $script_name -s $log_level "$log_info"
}
case $1 in
start)
# start listener
su - oracle -c "lsnrctl start"
retval=$?
if [ $retval -eq 0 ]then
clulog $LOG_INFO "oraShell: lsnrctl start succeeded."
else
clulog $LOG_ERR "oraShell: lsnrctl start failed, ret=$retval."
exit 1
fi
# start oracle
su - oracle -c "sqlplus /nolog" <<EOF
connect / as sysdba
startup
quit
EOF
ps -wwwef | grep ora_pmon | grep -v grep >/dev/null 2>&1
retval=$?
if [ $retval -eq 0 ]then
clulog $LOG_INFO "oraShell: oracle database start succeeded."
else
clulog $LOG_ERR "oraShell: oracle database start failed."
exit 1
fi
stop)
# stop listener
su - oracle -c "lsnrctl stop"
retval=$?
if [ $retval -eq 0 ]then
clulog $LOG_INFO "oraShell: lsnrctl stop succeeded."
else
clulog $LOG_ERR "oraShell: lsnrctl stop failed, ret=$retval."
exit 1
fi
# stop oracle
su - oracle -c "sqlplus /nolog" <<EOF
connect / as sysdba
shutdown immediate
quit
EOF
ps -wwwef | grep ora_pmon | grep -v grep >/dev/null 2>&1
retval=$?
if [ $retval -ne 0 ]then
clulog $LOG_INFO "oraShell: oracle database stop succeeded."
else
clulog $LOG_ERR "oraShell: oracle database stop failed."
exit 1
fi
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
# succeed
exit 0
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)