in that vein why not ....

snip----------

#!/usr/bin/perl 
use LWP::Simple;
print "The server is ",(get "http://www.essenz.com"; ? "up" : "down"),"\n";

snip----------

 :-P

Yours

Faye Gibbins
Linux, PERL and Duress. T.A.T.

"And his attitude towards his councils and towards each one of his advisers
should be such that they will recognize that the more freely they speak out
the more acceptable they will be... who does not is ruined by flatterers" --
Machiavelli


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:merlyn@;stonehenge.com]
Sent: 31 October 2002 13:15
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: How to verify that Web Server is up and running befor
sending HTTP request to it


>>>>> "Www" == Www  <[EMAIL PROTECTED]> writes:


Www> Here is the Code:


Www>    #!/usr/bin/perl

Www>    use LWP::UserAgent;

Www>         my $ua = LWP::UserAgent->new(env_proxy => 1,
Www>                                      keep_alive => 1,
Www>                                      timeout => 30,
Www>                                     );

Www>         $request = HTTP::Request->new('HEAD',
'http://www.essenz.com/');
Www>         $r = $ua->request($request);
Www>         %b = %{$r};

Www>         foreach $key (keys(%b))
Www>         {
Www>                 print "$key: $b{$key}\n";
Www>         }

Here is the Much Simpler Code:

    #!/usr/bin/perl

    use LWP::Simple;
    if (defined get "http://www.essenz.com";) {
      print "The server is up\n";
    } else {
      print "The server is down\n";
    }

If you get a 500 error, the response is undef.  If you get
a good page, the response is the content, which is not undef.

Please don't work harder than you need.


-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!

Intelligent Finance is a division of Halifax plc, Registered in England No. 2367076, 
Registered Office: Trinity Road, Halifax, West Yorkshire HX1 2RG.


Reply via email to