msk_0984 has asked for the wisdom of the Perl Monks concerning the following question:
I have a task in which we need to connect to remote system using a normal user and then switch to a different priviledged user to execute some priviledge commands. I am using Net::Telnet module to connect to remote systems and then have to use "su" to switch to the other user using Expect module.
But I am able to connect to the system using the normal user but as when we enter the command on the general terminal
It prompts for a password for that trying to use Expect module but I am unable to do it. I think am doing wrong here Here is a small script that I am trying to use# su -root -c 'command' Password:
I am unable to find any examples to do that and searched a lot but could not find any. Please guide me so that I can switch to the other user and use that telnet channel to execute priviledged commands and get the output.my $t = Net::Telnet->new( -host => $ip , -timeout => 60, -errmode => +"return"); do{ print qq{Failed open Telnet Session for '$host' }; exit 1; } unless ( $t ); $t->login( $user,$passwd ); do { print qq{Login Failed for '$host'} ; exit 1 } if ( $t->errmsg ); my $cmd1 = "\$OMNIHOME/bin/nco_ping NCO_PA "; my @out1 = $t->cmd(String => $cmd1, Timeout => 10 ); print " Out ==> @out1 \n"; my $exp = Expect->exp_init($t); $timeout = 3; $exp->expect($timeout, [ 'Password: $', sub { my $fh = shift; print $fh "$password\n"; exp_continue; } ], ); #my $cmd2 = "su root -c ls ";
Thanks In Advance
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Using Expect module in Net::Telnet
by msk_0984 (Friar) on Jun 27, 2008 at 21:09 UTC | |
by msk_0984 (Friar) on Jun 28, 2008 at 13:12 UTC | |
by Anonymous Monk on Jun 22, 2009 at 17:21 UTC |