在/etc/init.d下新建一个文件,比如就叫dbora。touch dbora;编辑此文件,粘贴以下脚本
#!/bin/sh
#chkconfig: 2345 80 80
#description:oracle auto startup and shutdown
#set oracle env
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
ORACLE_USER=oracle
#start or stop script
case "$1" in
'start')
su - "$ORACLE_USER"<<EOO
export ORACLE_SID=orcl
lsnrctl start
sqlplus /nolog<<EOS
connect / as sysdba
startup
EOS
EOO
;;
'stop')
su - "$ORACLE_USER"<<EOO
export ORACLE_SID=orcl
lsnrctl stop
sqlplus /nolog<<EOS
connect / as sysdba
shutdown immediate
EOS
EOO
;;
*)
echo "Usage: $0 {start|stop}"
;;
esac
保存。
chmod a+x dbora
chkconfig dbora on
即可。