写个脚本来启动数据库

每次打开Linux总要做写重复的动作,那就是启动监听,启动数据库,查看数据库状态。麻烦
还是写个shell脚本来控制方便些:
在$ORACLE_HOME/bin下有个dbstart脚本可以启动数据库,但是执行之后提示:
Failedtoauto-startOracleNetListeneusing/ade/vikrkuma_new/oracle/bin/tnslsnr
我们来查看下dbstart是怎么写的,直接查询查找文件中的报错来自哪里:
/Failedtoauto-startOracleNet
[oracle@localhostbin]$grep"Failedtoauto-startOracleNet"dbstart
echo"Failedtoauto-startOracleNetListeneusing$ORACLE_HOME_LISTNER/bin/tnslsnr"
在这之前有一句:
ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle
开来是路径设错了,修改为:
ORACLE_HOME_LISTNER=$ORACLE_HOME
报错重新执行下,没报错,但是数据库却没有起来,修改文件:
vi/etc/oratab
修改为:
orclsid:/home/oracle/oracle/product/10.2.0/db_1:Y
记住,后面为Y
再起,报错:
查看启动日志:
$ORACLE_HOME/startup.log
[oracle@localhostbin]$cat$ORACLE_HOME/startup.log
/home/oracle/oracle/product/10.2.0/db_1/bin/dbstart:Startingupdatabase"orclsid"
SatApr621:58:21CST2013
SQL*Plus:Release10.2.0.1.0-ProductiononSatApr621:58:212013
Copyright(c)1982,2005,Oracle.Allrightsreserved.
SQL>ERROR:
ORA-01031:insufficientprivileges
SQL>ORA-01031:insufficientprivileges
SQL>
/home/oracle/oracle/product/10.2.0/db_1/bin/dbstart:Databaseinstance"orclsid"warmstarted.
看来是权限问题,突然想到我之前修改了Oracle的默认认证方式,禁用了操作系统登录,估计在脚本里面使用的是操作系统登录:
一查,果然是这个问题:
修改为:connsys/lubinsuassysdba
重启下:
[oracle@localhostbin]$dbstart
ProcessingDatabaseinstance"orclsid":logfile/home/oracle/oracle/product/10.2.0/db_1/startup.log
/home/oracle/oracle/product/10.2.0/db_1/bin/dbstart:Startingupdatabase"orclsid"
SatApr622:25:27CST2013


SQL*Plus:Release10.2.0.1.0-ProductiononSatApr622:25:272013

Copyright(c)1982,2005,Oracle.Allrightsreserved.

SQL>Connectedtoanidleinstance.
SQL>ORACLEinstancestarted.

TotalSystemGlobalArea285212672bytes
FixedSize1218968bytes
VariableSize100664936bytes
DatabaseBuffers176160768bytes
RedoBuffers7168000bytes
Databasemounted.
Databaseopened.
SQL>DisconnectedfromOracleDatabase10gEnterpriseEditionRelease10.2.0.1.0-Production
WiththePartitioning,OLAPandDataMiningoptions

/home/oracle/oracle/product/10.2.0/db_1/bin/dbstart:Databaseinstance"orclsid"warmstarted.
看来已经起起来了,查看进程是否存在
[oracle@localhostbin]$ps-ef|grepora_pmon
oracle146581022:25?00:00:00ora_pmon_orclsid
oracle148069470022:26pts/100:00:00grepora_pmon
NICE
我们继续来写脚本:
#!/bin/bash
#
#chkconfig:23458920
#description:startstheoraclelistenerandinstance

status(){
pid=`ps-ef|grepora_pmon|grep-vgrep|awk'{print$8}'`
if["X$pid"="X"]
then
echo"oracle10gisnotrunning."
exit1
else
echo"oracle10gisrunning."
exit0
fi
}

case"$1"in
start)
#startupthelistenerandinstance
echo-n"oraclebegintostartup:"
su-oracle-c"lsnrctlstart"
su-oracle-cdbstart
echo"oracle10gstarted"
;;
stop)
#stoplistener,apacheanddatabase
echo-n"oraclebegintoshutdown:"
su-oracle-c"lsnrctlstop"
su-oracle-cdbshut
echo"oracle10gshutdowned"
;;
reload|restart)
$0stop
$0start
;;
'status')
status
;;
*)
echo"Usage:ora10g[start|stop|reload|restart]"
exit1
esac
exit0

赋给执行权限chmoda+xoracle10g
我们可以通过这个脚本来查看oracle的状态,启动,关闭或者重启数据库,方便许多。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值