in reply to threads, forks and SSH
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: threads, forks and SSH
by serf (Chaplain) on Dec 15, 2015 at 13:31 UTC | |
by ralph2014 (Initiate) on Dec 15, 2015 at 14:04 UTC | |
by salva (Canon) on Dec 15, 2015 at 14:15 UTC | |
by ralph2014 (Initiate) on Dec 15, 2015 at 23:45 UTC | |
by dasgar (Priest) on Dec 16, 2015 at 05:29 UTC | |
|