in reply to Re: Pinging.
in thread Pinging.

sorry formy stupidity, but how would you add a 'host is dead' print to this script? thanks

Replies are listed 'Best First'.
Re: Re: Re: Pinging.
by DigitalKitty (Parson) on Aug 08, 2002 at 00:00 UTC
    How would you add a 'host is dead' print to this script?

    Hi Anonymous Monk.
    #!/usr/bin/perl -w use strict; use Net::Ping; my $host; print "Host to ping? "; chomp( $host = <STDIN> ); my $p = Net::Ping->new(); if( $p->ping($host) ) { print "$host is alive!\n"; } else { print "$host appears to be dead.\n"; } $p->close();

    Hope this helps,
    -Katie.
Re: Re: Re: Pinging.
by Anonymous Monk on Aug 07, 2002 at 13:26 UTC
    aaarrrgghh, now i have a real problem. I forgot that the firewall between my server and the outside world drops ping requests. is there any way to check to see if my server is alive using a TCP connect method to see if it recieves a response form a port? i.e connect to port 25 and see if my smtp server responds? thanks

      You can do as follow:

      use Net::SMTP; @verify = ('smtp.host1.tld', 'smtp.host2.tld'); foreach $host (@verify) { $smtp = Net::SMTP->new($host); if (ref($smtp)) { print $smtp->banner(); } else { print "failed $host!\n"; } }

      This kind of check probably is better than pinging a host, but still doesn't tell you what is happening. A better solution would be to download a file from every remote host to be checked; if you can make these files contain some useful informations, like uptime, load average and disk usage, you can check what is happening and prevent also some kind of errors (i.e. disk full).
      You can generate those files automatically via a cron job and download them via HTTP or FTP, as you prefer.

      Ciao, Valerio