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