Check out the following script: I bet you can very easily tailor it to do exactly what you want. I use it for load-testing...
I *believe* this is the original "crashme" script from the mod_perl guide written by Stas Bekman (the script was written by someone else and modified by Stas). Not sure who the actual credit should go to...may have been written by Lincoln Stein come to think of it. Anyhow, here it is. #!/usr/local/bin/perl -w use LWP::Parallel::UserAgent; use Time::HiRes qw(gettimeofday tv_interval); use strict; ### # Configuration ### ## The numbers below should be changed to suit your needs, although this could work for you. my $nof_parallel_connections = 1; my $nof_requests_total = 1; my $timeout = 20; my @urls = ( 'http://your.site.here' ); ################################################## # Derived Class for latency timing ################################################## package MyParallelAgent; @MyParallelAgent::ISA = qw(LWP::Parallel::UserAgent); use strict; ### # Is called when connection is opened ### sub on_connect { my ($self, $request, $response, $entry) = @_; $self->{__start_times}->{$entry} = [Time::HiRes::gettimeofday]; } ### # Are called when connection is closed ### sub on_return { my ($self, $request, $response, $entry) = @_; my $start = $self->{__start_times}->{$entry}; $self->{__latency_total} += Time::HiRes::tv_interval($start); } sub on_failure { on_return(@_); # Same procedure } ### # Access function for new instance var ### sub get_latency_total { return shift->{__latency_total}; } ################################################## package main; ################################################## ### # Init parallel user agent ### my $ua = MyParallelAgent->new(); $ua->agent("pounder/1.0"); $ua->max_req($nof_parallel_connections); $ua->redirect(0); # No redirects ### # Register all requests ### foreach (1..$nof_requests_total) { foreach my $url (@urls) { my $request = HTTP::Request->new('GET', $url); $ua->register($request); } } ### # Launch processes and check time ### my $start_time = [gettimeofday]; my $results = $ua->wait($timeout); my $total_time = tv_interval($start_time); ### # Requests all done, check results ### my $succeeded = 0; my %errors = (); foreach my $entry (values %$results) { my $response = $entry->response(); if($response->is_success()) { $succeeded++; # Another satisfied customer } else { # Error, save the message $response->message("TIMEOUT") unless $response->code(); $errors{$response->message}++; } } ### # Format errors if any from %errors ### my $errors = join(',', map "$_ ($errors{$_})", keys %errors); $errors = "NONE" unless $errors; ### # Format results ### #@urls = map {($_,".")} @urls; my @P = ( "URL(s)" => join("\n\t\t ", @urls), "Total Requests" => "$nof_requests_total", "Parallel Agents" => $nof_parallel_connections, "Succeeded" => sprintf("$succeeded (%.2f%%)\n", $succeeded * 100 / $nof_requests_total), "Errors" => $errors, "Total Time" => sprintf("%.2f secs\n", $total_time), "Throughput" => sprintf("%.2f Requests/sec\n", $nof_requests_total / $total_time), "Latency" => sprintf("%.2f secs/Request", ($ua->get_latency_total() || 0) / $nof_requests_total), ); my ($left, $right); ### # Print out statistics ### format STDOUT = @<<<<<<<<<<<<<<< @* "$left:", $right .. while(($left, $right) = splice(@P, 0, 2)) { write; } __END__ Hope this helps...works like a champ for me. Matt --- rory o'connor <[EMAIL PROTECTED]> wrote: > I'm not sure if perl is best suited for this project - but I bet it is! I > need to call a server (perhaps via lynx?) in a cron'd script and then time > how long it takes for the page to load. > > The reason is that sometimes the remote server stops loading pages due to > some unknown problem (this is nt4.0, mind you). while we try to figure it > out, i need to be alerted via email when it hasn't finished loading the page > in say, 20 seconds - because the server needs to be restarted. > > any input on how to approach this little project is appreciated! > > thanks, > > rory > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > __________________________________________________ Do You Yahoo!? Send your FREE holiday greetings online! http://greetings.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]