For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2007 > Simple loop issue









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Simple loop issue
Javier Prats

2007-07-23, 6:59 pm

Hello everyone,

I created this simple script as a temporary remedy for IIS. It seems to
be going down once a day. We're waiting on new hardware which will be
running LAMP instead. In the mean time this Perl script below was
created to check the services and bring them up if they are not running.
I am new to programming, Perl, and Mechanize. For some strange reason
when the "while" test is done it sees the site down and runs the batch
script to restart the server. This script is cycling the IIS server
every two minutes. Can anyone explain what I am missing? It seemed
pretty straight forward to me.


#!/usr/local/bin/perl

use WWW::Mechanize;
use diagnostics;
use strict;

my $mech =3D WWW::Mechanize->new( autocheck =3D> 0);

# IP is being used because there are to mirrored
# servers using the same hostname and load balanced.
#

my $url =3D "http://my_server_ip_here";
my $trick =3D 0;

while ($trick =3D=3D 0) {
$mech->get( $url );

if ($mech->success){
;
}

else {
system "c:\\my.bat";
}

sleep 120;
}


Javier Prats
Technical Project Coordinator
Taylor & Francis Group, LLC
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487


yaron@kahanovitch.com

2007-07-23, 6:59 pm

Hi,

Is you can see the web site is not accessible.
I think that you should test the HTTP::Response and get the error:

my $res = $mech->get( $url );
unless ($res->is_success) {
print STDERR "Error: ",$r->status_line,"\n";
....

}

see http://search.cpan.org/~gaas/libwww.../HTTP/Status.pm for details


Hope that helps


Yaron Kahanovitch
----- Original Message -----
From: "Javier Prats" <javier.prats@taylorandfrancis.com>
To: beginners@perl.org
Sent: Monday, July 23, 2007 5:04:58 PM (GMT+0200) Auto-Detected
Subject: Simple loop issue

Hello everyone,

I created this simple script as a temporary remedy for IIS. It seems to
be going down once a day. We're waiting on new hardware which will be
running LAMP instead. In the mean time this Perl script below was
created to check the services and bring them up if they are not running.
I am new to programming, Perl, and Mechanize. For some strange reason
when the "while" test is done it sees the site down and runs the batch
script to restart the server. This script is cycling the IIS server
every two minutes. Can anyone explain what I am missing? It seemed
pretty straight forward to me.


#!/usr/local/bin/perl

use WWW::Mechanize;
use diagnostics;
use strict;

my $mech = WWW::Mechanize->new( autocheck => 0);

# IP is being used because there are to mirrored
# servers using the same hostname and load balanced.
#

my $url = "http://my_server_ip_here";
my $trick = 0;

while ($trick == 0) {
$mech->get( $url );

if ($mech->success){
;
}

else {
system "c:\\my.bat";
}

sleep 120;
}


Javier Prats
Technical Project Coordinator
Taylor & Francis Group, LLC
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487



--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com