Admin-Stress wrote:

> Hi, I wrote a script to test if a http server is OK.
> My method is :
> - telnet to por 80
> - send any text
> 
> If the http server is OK, it will return "some" text, and should contain
> string </html>
> 
> So, I assume, if I can catch </html>, then my http server is OK.
> 
> Here is my perl script:
> 
>    use Net::Telnet;
> 
>    sub error {
>      print -255;
>      exit(0);
>    }
> 
>    print "Testing http at $ARGV[0]\n";
> 
>    $telnet = new Net::Telnet ( Timeout=>30, Port=>80, Errmode=>error );
>    $telnet->open($ARGV[0]);
>    $telnet->print('TESTING');
>    $telnet->waitfor('/<\/html>/');
>    print 0;
> 
> The problem is, it always result -255 ... sub error called.
> However, if I set Errmode=>'die', it will result 0.
> 
> Anyone know how to setup Errmode with a subroutine?
> 
> And, is my method good for testing http server? I just want as simple as
> possible.
> 

Have you try changing:

Erromode=>error

to:

Errormode=>\&error

this should do the trick. However, it sounds a little odd to use the Telnet 
module to test a http server especially there are other modules that are 
designed to work with the http protocal. will something like:

#!/usr/bin/perl -w
use strict;

use LWP::UserAgent;

my $agent = LWP::UserAgent->new;
my $req = HTTP::Request->new(HEAD => 'http://www.google.com');
my $res = $agent->request($req);

if($res->is_success){
        print "google up\n";
}else{
        print "google down?\n";
}

__END__

make more sense?

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to