1748265 Members
3740 Online
108760 Solutions
New Discussion

Re: Script help.

 
SOLVED
Go to solution
H.Merijn Brand (procura
Honored Contributor

Re: Script help.

Why use external commands if perl supports this though modules extremely well?

#!/usr/bin/perl

use strict;
use warnings;
use LWP;
use LWP::UserAgent;
use Mail::Sendmail;

my %apps = (
    appnameA => "boxA.foobar.com",
    appnameB => "boxB.foobar.com",
    appnameC => "boxC.foobar.com",
    );
my $port = 5000;
my $ua = LWP::UserAgent->new (
    agent      => "Opera/11.00 opera 11",
    cookie_jar => {},
    );

while (my ($service, $box) = each %apps) {
    my $url = qq(http://$box:$port/segment/region/phase/dest?app=$service);
    my $rsp = $ua->request (HTTP::Request->new (GET => $url));

    $rsp->is_success or die "get failed: ", $rsp->status_line, "\n";
    if ($rsp->content =~ m/DISABLED/) {
        sendmail (
            To      => 'allanm@foobar.com',
            From    => 'me@this.box',
            Subject => "$service down on $box",
            Message => "Please fix",
            ) or die $Mail::Sendmail::error;
        }
    }

 

 

Enjoy, Have FUN! H.Merijn
James R. Ferguson
Acclaimed Contributor

Re: Script help.


@H.Merijn Brand (procura wrote:

Why use external commands if perl supports this though modules extremely well?


I agree, particularly from a portability standpoint.   Of course, Allan is probably running Perl 5.8.8 from the standard HP-UX distributions.  He would need to install the LWP::UserAgent (perhaps) and Mail::SendMail from CPAN.  While this is trivial, some sites are reticent in these regards :-(

 

Regards!

 

...JRF...