Network Admin   «Prev  Next»

Lesson 6 Start Net services with line commands
Objective Start a listener with line commands.

Start Net Services with Line Commands

There is a simple line command controller called the Listener Controller (lsnrctl) that can be used to start and stop a Net listener.
Let us take a look at how this works. The following simulation starts up a listener on Windows NT. You must be at the operating system command prompt to begin. For this example, we are using Windows NT with an MS-DOS prompt screen. The same commands work on the UNIX and Linux platforms.
Navigate through the simulation to see how to use the Listener Controller.

Start Net services with line commands

  1. Start the Listener Controller by typing the following command and then pressing Enter: lsnrctl
  2. You can see that you are in the Listener Controller because the prompt has changed to LSNRCTL>. To view the status of all listeners on this node, type this command and press Enter: status
  3. As you can see, the listener named LISTENER has been up and running for 1 hour, 9 minutes, and 43 seconds. Shut down the listener by typing this command and pressing Enter: stop
  4. Listener Controller displays feedback indicating that your command worked. Now, start the listener by typing this command and pressing Enter: start
  5. Listener Controller displays a great deal of status information, and then displays the status of the listeners that it started. Exit the Listener Controller by typing this command and pressing Enter: exit
  6. Listener Controller ends and your prompt returns to the normal operating system prompt.

As you can see from the simulation, the Listener Controller uses simple commands to control the background listener processes on your computer. The next lesson will describe the uses of the Net Configuration Assistant.
The following section describes starting listener using line commands in Oracle.

Start Listener Line Commands

The following commands are used to Start listener with line commands:
  1. lsnrctl: This starts the Listener Controller.
  2. status: This displays the current status of the listener.
  3. stop: This stops the listener service.
  4. start: This starts the listener service.
  5. exit: This closes the Listener Controller.

Here we see the lsnrctl command in action:
$ lsnrctl
LSNRCTL for Solaris: Version 9.2.0.1.0 - Production on 28-FEB-2004 11:53:14

(c) Copyright 1999 Oracle Corporation.  All rights reserved.

Welcome to LSNRCTL, type "help" for information.
LSNRCTL> help

The following lsnrctl operations are available An asterisk (*) denotes a modifier or extended command:
 start               stop                status

 services            version             reload

 save_config         trace               spawn

 dbsnmp_start        dbsnmp_stop         dbsnmp_status

 change_password     quit                exit

 set*                show*


The following commands are used to manage the listener:
  1. services: Displays each service available, along with the connection history.
  2. version: Displays the version information of the listener.
  3. reload: Forces a read of the configuration file in order for new settings to take effect without stopping and starting the listener.
  4. save_config: Creates a backup of the existing listener.ora file and saves changes to the current version.
  5. trace: Sets the trace level to one of the following OFF, USER, ADMIN, or SUPPORT.
  6. spawn: Spawns a program that runs with an alias in the listener.ora file.
  7. dbsnmp_start: Starts the DBSNMP subagent.
  8. dbsnmp_stop: Stops the DBSNMP subagent.
  9. dbsnmp_status: Displays the status of the DBSNMP subagent.
  10. change_password: Sets a new password for the listener.
  11. quit or exit: Exits the lsnrctl utility.
  12. set: Changes the value of any parameter. Everything that can be shown can be set.
  13. show: Displays current parameter settings.

Question: How do I write a shell script to start my listener?
In addition, I also want to write a script to check to see if my listener is running.
Answer: This script uses the exit status from the lsnrctl command to determine the success or failure of the command. If lsnrctl status returns a 0 we know the command ran successfully and the listener is running. In this case, the script does not send any notifications, instead it just removes the temp file.
If, however, the lsnrctl has a non-zero exit status we know there is a problem. The script will then execute a lsnrctl start command and send an email.
check_listener.sh
 #!/bin/bash 
# If a SID is provided as an argument it will be set and oraenv run
# otherwise we will use the current SID. If no SID is set or provided
# an error message is displayed and the script exits with a status of 1
if [ $1 ]
then
 ORACLE_SID=$1
ORAENV_ASK=NO
. oraenv
else
if [ ! $ORACLE_SID ]
then
echo "Error: No ORACLE_SID set or provided as an argument"
exit 1
#  Now check the listener status with ps -ef | grep -i lsnr
#  Then re-start the listener if it has crashed and send an e-mail alert

Ad Oracle Integration Cloud Service