From: Sai Kiran on

Hi,

I have a requirement where i need to login to a remote server and then
su to another user for executing commands. The problem that i am facing
is that i am not able to find how to pass the password for the su
command after i login into the remote system.

My code looks like this?

#!/usr/bin/perl

use strict;
use warnings;
use Net::SSH::Perl;

my ($host,$user,$pass);


( $host, $user, $pass ) = ('hostname', 'username', 'passwd' );
my $conn = Net::SSH::Perl->new($host,"protocol 2,1");
$conn->login($user,$pass);
my ( $out,$err,$exit) = $conn->cmd('su - username "ls -l"
','password');
print " -------- $host -----------\n";
if ( $exit == 0 )
{ print $out."\n"; }
else
{ print $err."\n"; }



any pointers on where i going wrong?

I know that password cannot be passed as stdin to su. Any other ideas
or suggestion are highly welcome.

Thanking you.

From: usenet on
Sai Kiran wrote:
> is that i am not able to find how to pass the password for the su
> command after i login into the remote system.

The only way I know of to do that is by the use of Expect:

http://search.cpan.org/~rgiersig/Expect-1.20/Expect.pod


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)

From: Sai Kiran on


On Jan 4, 10:53 pm, use...(a)DavidFilmer.com wrote:
> Sai Kiran wrote:
> > is that i am not able to find how to pass the password for the su
> > command after i login into the remote system.The only way I know of to do that is by the use of Expect:

> David Filmer (http://DavidFilmer.com)


Thanks David.