Net::SSH::Perl question

S

Sai Kiran

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top