[unisog] script (perl ?) for monitoring connectivity to a few web sites

Russell Fulton r.fulton at auckland.ac.nz
Sun Jun 20 21:49:20 GMT 2004

On Sun, 2004-06-20 at 11:26, Russell Fulton wrote:
> HI All,
> 	I need a quick and dirty script to monitor http connectivity to a
> couple of machines.  I could write one myself but I hate reinventing the
> wheel and I am short of time so I thought I would ask.

I ended up writing one myself, it turns out to be pretty trivial:

#! /usr/bin/perl -w
use strict;
use IO::Socket::SSL;
use LWP::UserAgent;

# urls to monitor

my @urls = qw (

my $ua = new LWP::UserAgent(timeout => 5);
my $resp;

for(;;sleep(5)) {  # ever and ever

    foreach my $url (  @urls ) {
	print STDERR $url ;
	print STDERR "\a\a\a\a HEAD failed :$resp->{_msg}"
	    unless ( $resp=$ua->head($url) )->is_success;
	print STDERR "\n" ;

It works fine for http but the short timeouts don't work for https. 
I.e. when it trys an https site that it can not connect to it waits 5
minutes before returning and complaining.  For my current need I need
much faster reaction time than this.  I am currently corresponding with
the author of IO::Socket::SSL.

While the base script took 15 minutes to get going I spent all Sunday
afternoon fighting the timeout problem.

Cheers, Russell

More information about the unisog mailing list