« Apache rewrite rules for hosting multiple domains | Home | Redirect script output to the log »

Setting password for Oracle listener in the script

Oracle listener control utility doesn't allow to set the password non-interactively.
In this case the small Perl script, using Expect, could help.


#!/usr/bin/perl
use Expect;
my $exp = new Expect;

my $command = 'lsnrctl';
my $PROMPT='LSNRCTL>';

my $LISTENER_NAME=$ARGV[0] ;
my $NEW_PASSWORD=$ARGV[1] ;
print "Changing pasword for ${LISTENER_NAME} \n" ;

$exp->spawn($command) or die "Cannot spawn $command: $!\n";

$exp->stty(qw(echo));

my $answer = $exp->expect(30, 'LSNRCTL>');
$exp->send("set current_listener ${LISTENER_NAME}\n");

$answer = $exp->expect(30, $PROMPT);
$exp->send("change_pass\n");

# For localized version should be changed (i.e. just to ':')
$answer = $exp->expect(30, 'Old password:');
# It's supposed, that listener still doesn't have the password
$exp->send("\n");

$answer = $exp->expect(30, 'New password:');
$exp->send("${NEW_PASSWORD}\n");

$answer = $exp->expect(30, 'Reenter new password:');
$exp->send("${NEW_PASSWORD}\n");

$answer = $exp->expect(30, $PROMPT);
$exp->send("set password\n");

$answer = $exp->expect(30, 'Password:');
$exp->send("${NEW_PASSWORD}\n");

$answer = $exp->expect(30, $PROMPT);
$exp->send("save_config\n");

# Restart it if necessary
# $answer = $exp->expect(30, $PROMPT);
# $exp->send("reload\n");

$answer = $exp->expect(30, $PROMPT);
$exp->send("exit\n");

exit;

Topics: Oracle, expect, password, perl | Submitter: checkthis

One Response to “Setting password for Oracle listener in the script”

  1. sweetj Says:
    September 22nd, 2008 at 8:32 am

    Since I do not have access to getting new modules is there another way using Perl to automate change_password for the listener. olsd_password is null and I pull a new password from a file. I need that to be defaulted in and then re-entered and also order the save_config. I don't have access to Expect or IPC::Run. I was told you can use IPC::Open3. The issue is I am a novice and this is has been a very difficult task. Any help would be very much appreciated.

    Thanks,
    Jerrianna

Comments

You must be logged in to post a comment.