Salav

thx a lot. I was able to use all the ssh options i need.

last thing i need to understand is how to redirect the output to a local file 
from all the commands:

how to redirect the out of the following to a file handle?


$pssh->push('*', command => @MFCMDS);



I tried: but not working???

@result = $pssh->run;




thx.
Rajeev



________________________________
From: salva <sfand...@gmail.com>
To: beginners@perl.org
Sent: Thursday, November 10, 2011 4:51 AM
Subject: Re: is this ssh happenign in parallel?

On Nov 8, 12:56 am, rp.ne...@yahoo.com (Rajeev Prasad) wrote:
> using the async option in Net::OpenSSH
>
> can someone help me understand whether in second loop commands are being 
> executed without waiting for them to complete, so that parallelism is 
> achieved as indicated by using async option?
>
> if not, then how can we achieve to execute the commands on remote hosts in 
> parallel using Net::OpenSSH?
>
> my @hosts =qw(...);  #all hosts
> my @allcmds = qw(...);   #all commands
>
>     for my $host (@hosts){            #loop to process all host in list
>     chomp($host);
>     $ssh{$host} = Net::OpenSSH->new($host,
>                             port => $SSHPORT,
>                             user => $USER,
>                             password => $PASS,
>                             default_stderr_fh => $stderr_fh,
>                             default_stdout_fh => $stdout_fh,
>                             async => 1,
>                             master_opts => [-o => 'StrictHostKeyChecking=no',
>                                                  -o => 'ConnectTimeout 10'],
>                             );
>     }
>
> open(MFOH,">>$MFRESULT");
>
>     for my $host (@hosts) {
>         foreach $CMD (@allcmds){
>             chomp($CMD);
>             ( @CMDRESULT, $CMDERR ) = $ssh{$host}->capture("$CMD");
>             print MFOH "\n$host COMMAND: $CMD\n";
>             foreach my $line (@CMDRESULT) { print MFOH "$host $line"; }
>             @CMDRESULT = "";
>             if (defined $CMDERR ) {print MFOH "$host $CMDERR \n"; $CMDERR = 
> "";}
>             }
>         }
> close MFOH;
>
> ....

The capture method does not work asynchronously.

For that you will have to run the commands with the pipe_out method
and capture the output of all the commands in parallel using a select
loop or POE or AnyEvent.

Alternatively use Net::OpenSSH::Parallel


--
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