Salva,

can you explain how to use variable expansion in your written module 
Net::Openssh and Net::Openssh::Parallel ? I want to be able to specify userid 
and password for the parallel ssh sessions using Net::Openssh::Parallel ...

thank you.
Rajeev


Variable expansion
This module activates Net::OpenSSH variable expansion by default. That way, it 
is possible to easily customize the actions executed on every host in base to 
some of its properties.
For instance:
$pssh->push('*', scp_get => "/var/log/messages", "messages.%HOST%");
copies the log files appending the name of the remote hosts to the local file 
names.
The variables HOST, USER, PORT and LABEL are predefined.




________________________________
From: Rajeev Prasad <rp.ne...@yahoo.com>
To: salva <sfand...@gmail.com>; "beginners@perl.org" <beginners@perl.org>
Sent: Thursday, November 10, 2011 8:50 AM
Subject: Re: is this ssh happenign in parallel?

Hello Salva,

I want to use Net::OpenSSH::Parallel, but i could not figure:

1. how to supply username and password to each connection?
2. can i write output from all sessions to a single local file?


thank you.



________________________________
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