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?
<code>
#!/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"; }
</code>
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.
To write a respons, access
http://ww
w.cpanforum.com/response_form/3973
To see the full thread, access
http://www.cpan
forum.com/threads/3973
--
You are getting this messages from www.cpanforum.com
To change your subscription information visit http://www.cpanforum.
com/mypan/
|