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:

#Start/Stop script for oracle

case "$1" in

su - oracle <<END_SU

#start databases

#start oracle listener
lsnrctl start



#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

#cleanly shutdown immediate databases

echo "Usage: $0 { start | stop }"
exit 0
January 11, 2007

  • Thanks again. Had I known password wasn’t needed for startup, I might have been tempted to be lazy and skip the listener shutdown step, since I’m a lot less bothered about a listener not being cleanly shutdown than a database.

  • I’m following these steps exactly, but seeing that my script is not able to set variables within the “su – ” routine.

    This is happening both on my RHES Linux 4.0 and hpux 11.11 servers.

    If I put all the oracle commands in a separate script, then everything is fine, but I’m wondering if anyone knows why the example above wouldn’t work for me?


  • Not sure why that happens, but I just replicated it on a solaris test machine. Fix I used there was to take the environment variable line:

    ENCRYPTED_PASSWORD=`grep -i password /etc/listener.ora | awk -F= ‘{print $2}’ -`

    to be before the su.

    I’ve updated the original post to have that fix in.

  • The ‘start’ or ‘stop’ is passed to the script as the first parameter, ‘$1’.

    So from the command line you would type e.g.: “/etc/init.d/oracle start” or use it’s alias: “service oracle start”

    And the good thing is that server shutdowns and startups automatically pass in either ‘start’ or ‘stop’ to the scripts in /etc/init.d.

  • Leave a Reply

    Your email address will not be published. Required fields are marked *