Thread

Posted on Thu Jan 4 14:53:35 2007 by saikiran
executting su
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.
Write a response