in reply to threads, forks and SSH

You can use Net::OpenSSH::Parallel for that:
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
    Meh about:
    system 'cat $host.csv'; system 'rm $host.csv';

    You have open and print, you have unlink, and you have ways of checking that what you wanted to do worked correctly.

    Perl isn't a shell script.

    I would suggest that it's more reliable, more efficient, more cross-OS portable, and generally better practice to do these things natively in Perl than shelling out via system.

    I get given grief at my $JOB by "scripts" that people who don't know Perl have written in Perl which should be in Perl but are full of awk and sed and grep and wc pipes and other badness. These scripts spawn many more processes than they need to, use more memory, and end up doing knarly things like jamming up, failing silently or causing excessive IO over NFS etc, bringing down our systems.

    When we post code on perlmonks, people who don't know as much as we do will take what we've written without understanding it and use it thinking it's the *right* way to do it. I think we should try and be responsible and steer them in the right direction.

    /me dismounts soapbox

      Morning again Monks! Thank you so much for the replies. This module sounds just what im looking for. Im not too bothered about things being a little dirty aslong as it gets it done quickly and I get decent output. I should add its a windows server 2003. ralph
        Oops, then you can not use it: Net::OpenSSH does not work on Windows.

        Your best option there is to go for Net::SSH2 or Net::SSH::Perl, but IIRC, both have issues with threads.

        A reply falls below the community's threshold of quality. You may see it by logging in.