From bbb0b7f6ddc7057ef7eb231b8e5b03d063f215f0 Mon Sep 17 00:00:00 2001 From: hjp Date: Wed, 30 Apr 2008 11:58:46 +0000 Subject: [PATCH] Script to ping multiple hosts in parallel --- multiping/multiping | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 multiping/multiping diff --git a/multiping/multiping b/multiping/multiping new file mode 100755 index 0000000..4a7aa71 --- /dev/null +++ b/multiping/multiping @@ -0,0 +1,31 @@ +#!/usr/bin/perl +use warnings; +use strict; + +use IO::Select; + +my $s = IO::Select->new(); + +my %fh2host; +my $len = 0; +for my $host (@ARGV) { + open(my $fh, '-|', 'ping', $host) or die "cannot exec ping: $!"; + $s->add($fh); + $fh2host{$fh} = $host; + $len = length($host) if length($host) > $len; +} +my %state; + +for (;;) { + my @ready = $s->can_read(1); + for my $fh (@ready) { + my $msg = <$fh>; + chomp($msg); + my $host = $fh2host{$fh}; + $state{$host} = $msg; + } + print "\n\n"; + for my $host (@ARGV) { + printf("%-*s : %s\n", $len, $host, $state{$host}); + } +}