9i unix startup / shutdown with listener password
Thanks to Laurent Schneider for tips on how to handle listener passwords in scripts. [Update 12-Jan-2007 – ammended script following Laurent’s comment, and update 09-Feb-2007 – ammended script following Kevin’s comment]
A system startup/shutdown shell script I just used that copes with listener passwords is below.
The location of the listener.ora file was /etc in my case, but that can be different in other servers. The script assumes oracle environment variables are all set correctly at login (the “su -“). This is 9i specific – as explained on Laurent Schneider’s blog post, things are different/better with 10g. Also is only designed to work with a single listener with the default name, LISTENER).
For this script to actually run at system startup/shutdown time, it needs to be linked into the /etc/rc*.d directories, at least /etc/rc3.d (the default startup/shutdown level) although I put it in the others also. The easiest way to do this is using the “chkconfig –add oracle” utility, but it can also be done manually as root user:
vi /etc/init.d/oracle [pasted in below shell script] chmod 755 /etc/init.d/oracle cd /etc/rc1.d ln -s ../init.d/oracle K99oracle ln -s ../init.d/oracle S99oracle cd /etc/rc2.d ln -s ../init.d/oracle K99oracle ln -s ../init.d/oracle S99oracle cd /etc/rc3.d ln -s ../init.d/oracle K99oracle ln -s ../init.d/oracle S99oracle cd /etc/rc4.d ln -s ../init.d/oracle K99oracle ln -s ../init.d/oracle S99oracle cd /etc/rc5.d ln -s ../init.d/oracle K99oracle ln -s ../init.d/oracle S99oracle cd /etc/rc6.d ln -s ../init.d/oracle K99oracle ln -s ../init.d/oracle S99oracle
The script Itself:
#!/bin/sh
#
#Start/Stop script for oracle
#
case "$1" in
'start')
su - oracle <<END_SU
#start databases
dbstart
#start oracle listener
lsnrctl start
END_SU
;;
'stop')
#stop oracle 9i listener with password control
ENCRYPTED_PASSWORD=`grep -i password /etc/listener.ora | awk -F= '{print $2}' -`
su - oracle <<END_SU
lsnrctl <<END_LISTENER
set password $ENCRYPTED_PASSWORD
stop
quit
END_LISTENER
#cleanly shutdown immediate databases
dbshut
END_SU
;;
*)
echo "Usage: $0 { start | stop }"
;;
esac
exit 0
note that you never need a password to start a listener 8)
take care if you have more than one listener