crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs | LICENSE

xr-is-live (813B)


      1 #!/usr/bin/perl
      2 
      3 use strict;
      4 
      5 die <<"ENDUSAGE" if ($#ARGV < 0);
      6 
      7 Usage: xr-is-live HOST [HOST...]
      8 
      9 Polls stated host(s) for live status. Exits with the number of unreachable
     10 hosts.
     11 
     12 Sample usage:
     13   xr-is-live onehost        - checks if the one host is down
     14   xr-is-live h1 h2 h3 h3 h5 - checks if this network is down (this can be
     15                               assumed when exit status is larger than 3)
     16 
     17 ENDUSAGE
     18 
     19 for my $h (@ARGV) {
     20     next if fork();
     21     if (!testlive($h)) {
     22 	print ("$h is not reachable\n");
     23 	exit (1);
     24     }
     25     exit (0);
     26 }
     27 my $ret = 0;
     28 while (1) {
     29     last if (wait() == -1);
     30     $ret++ if ($?);
     31 }
     32 
     33 print ("total $ret not reachable host(s)\n") if ($ret);
     34 exit ($ret);
     35 
     36 sub testlive($) {
     37     my $h = shift;
     38 
     39     system("ping -c3 -t1 '$h' >/dev/null") and return undef;
     40     return 1;
     41 }
     42