Hello Salva,

I tried many ways this is not happening. can you help? ( I did not try the 

there is nothing printed in results. single word commands like ls pwd are also 
not producing anything.

since CU sudo does not allow more than 1 option at a time, i supply -k before 
supplying the command.

please note that this sudo version does not have -S switch to pass password 
using stdin. so it expects password from terminal. can u pl help more. thx.


                $ssh->system("$sudo_path -k");
                my @output = $ssh->capture({tty => 1,
                               stdin_data => "$PASS"},
                              $sudo_path,
                              "-p",'', "$cmd");
                print "  result=@output \n";



OR

                $ssh->system("$sudo_path -k");
                my @output = $ssh->capture({stdin_data => "$PASS"},
                              $sudo_path,
                              "-p",'', "$cmd");
                print "  result=@output \n";




________________________________
 From: Salvador Fandino <sfand...@yahoo.com>
To: Rajeev Prasad <rp.ne...@yahoo.com> 
Cc: David Precious <dav...@preshweb.co.uk>; perl list <beginners@perl.org> 
Sent: Friday, September 7, 2012 2:10 AM
Subject: Re: expect.pm not recognising match string
 
On 09/07/2012 12:54 AM, Rajeev Prasad wrote:
> no because first i have to sudo to some other ID and then run commands.....

You should be able to call every command through 'sudo', something like this:

  $ssh->capture('sudo', @sudo_opts, @cmd1);
  $ssh->capture('sudo', @sudo_opts, @cmd2);

There are several versions of sudo with different capabilities and besides 
that, its configuration also varies widely between operating systems and 
distributions. So you may have to experiment a lot in order to find the right 
set of arguments that gets it to work.

Some things that may help:

Asking Net::OpenSSH to allocate a tty for the channel:

  $ssh->capture({ tty => 1, ... }, 'sudo', ...);

You should be able to pass the password through stdin without using Expect:

  $ssh->capture({ stdin_data => "$password\n", ...}, ...);

And read the sudo documentation for the specific version used on the target 
hosts.


-- To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/

Reply via email to