use Net::OpenSSH::Parallel; my @hosts = (...); my $pssh = Net::OpenSSH::Parallel; # register the list of hosts: $pssh->add_host($_) for @hosts; # declare the commands you want to run in every host: $pssh->push('*', cmd => 'do.this'); $pssh->push('*', cmd => 'do.that'); $pssh->push('*', { stdout_file => '%HOST%.csv' }, # %HOST% is replaced by t +he host name cmd => 'make.csv'); # let Net::OpenSSH::Parallel take care of everything: $pssh->run; # finally, collect the errors and the temporary CSV files. for my $host (@hosts) { my $error = $pssh->get_error($host); if ($error) { print STDERR "Failed to generate CSV from host '$host': $error\n"; } else { system cat => "$host.csv"; unlink "$host.csv"; } }
update: code adjusted according to some of the comments by serf below.
In reply to Re: threads, forks and SSH
by salva
in thread threads, forks and SSH
by ralph2014
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |