File: filter_output.pl

package info (click to toggle)
libnet-openssh-parallel-perl 0.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 160 kB
  • sloc: perl: 947; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 617 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/perl

use strict;
use warnings;

use Net::OpenSSH::Parallel;
use POSIX ();

my @hosts = qw(localhost 127.0.0.1 192.168.21.1);

my $pssh = Net::OpenSSH::Parallel->new;

my %filter_fh;
for my $host (@hosts) {

    my $pid = open my $out, '|-';
    unless ($pid) {
        defined $pid or die "unable to fork filter process: $!";
        $| = 1;
        while (<>) {
            print "$host: $_";
        }
        POSIX::_exit(0);
    }

    $filter_fh{$host} = $out;

    $pssh->add_host($host, default_stdout_fh => $out);
}

$pssh->push('*', cmd => 'find /');
$pssh->run;

close $_ for values %filter_fh;