1 |
#!/usr/bin/perl |
#!/usr/bin/perl -w |
2 |
# |
# |
3 |
# Return a list of hosts which not reachable via ICMP echo |
# Return a list of hosts which not reachable via ICMP echo |
4 |
# |
# |
5 |
# Jim Trocki, trockij@transmeta.com |
# Jim Trocki, trockij@transmeta.com |
6 |
# |
# |
7 |
|
# This module is modified to recognize hosts in format |
8 |
|
# username[:password]@host/database ... |
9 |
|
# which is used my pgsql.monitor (of course, just host is used) by |
10 |
|
# Dobrica Pavlinusic, dpavlin@rot13.org |
11 |
|
# http://www.rot13.org/~dpavlin/sysadm.html |
12 |
|
# |
13 |
# $Id$ |
# $Id$ |
14 |
# |
# |
15 |
# Copyright (C) 1998, Jim Trocki |
# Copyright (C) 1998, Jim Trocki |
62 |
|
|
63 |
exit 0 if (@ARGV == 0); |
exit 0 if (@ARGV == 0); |
64 |
|
|
65 |
open (IN, "$CMD @ARGV 2>&1 |") || |
my @hosts; |
66 |
|
|
67 |
|
# you can use hosts in format host:optional configuration parameters and |
68 |
|
# this part will strip everything after hostname |
69 |
|
foreach (@ARGV) { |
70 |
|
if (m/^[^:]+:?[^\@]*\@([^\/]+)\/?.*/) { |
71 |
|
my $host = $1; |
72 |
|
push @hosts,$host if (! grep /^$host$/,@hosts); |
73 |
|
} else { |
74 |
|
push @hosts,$_ if (! grep /^$_$/,@hosts); |
75 |
|
} |
76 |
|
} |
77 |
|
|
78 |
|
open (IN, "$CMD @hosts 2>&1 |") || |
79 |
die "could not open pipe to fping: $!\n"; |
die "could not open pipe to fping: $!\n"; |
80 |
|
|
81 |
my @unreachable; |
my @unreachable; |
86 |
my @icmp; # ICMP messages output by fping |
my @icmp; # ICMP messages output by fping |
87 |
my %addr_unknown; |
my %addr_unknown; |
88 |
|
|
89 |
my %want_host = map { $_ => 1 } @ARGV; # hosts fping hasn't output yet |
my %want_host = map { $_ => 1 } @hosts; # hosts fping hasn't output yet |
90 |
|
|
91 |
while (<IN>) |
while (<IN>) |
92 |
{ |
{ |