<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Script help. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5311309#M641952</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.hpe.com/t5/user/viewprofilepage/user-id/1196371"&gt;@allanm77&lt;/a&gt; wrote:&lt;BR /&gt;Hi JRF,&lt;BR /&gt;Can you provide the perl equivalent of the shell script..&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;OK, here's one possibility.&amp;nbsp; I am going to assume that you have some knowledge of Perl and/or that you will dig with this as an example :-)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#!/usr/bin/perl
use strict;
use warnings;

my $SERVICE1 = q(appnameA);
my $BOX1     = q(boxA.foobar.com);
my $PORT1    = 5000;

my $result =
    qx(curl -s "http://$BOX1:$PORT1/segment/region/phase/dest?app=$SERVICE1");
my $rc = $?;&lt;BR /&gt;&lt;BR /&gt;die "Can't fetch URL; return code = ", +($rc &amp;gt;&amp;gt; 8), "\n" unless $rc == 0;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;if ( $result =~ m{DISABLED} ) {
    system qq( mail -s "$SERVICE1 is down" allanm\@foobar.com &amp;lt;/dev/null );
}
1;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
    <pubDate>Wed, 24 Aug 2011 19:16:24 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2011-08-24T19:16:24Z</dc:date>
    <item>
      <title>Script help.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5310169#M641947</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Created a piece of shell script, want to iterate the curl statement and if condition for multiple Services,boxes combination (within the same script) and send multiple emails if the condition is met.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If possible would prefer this to be converted to perl.&lt;/P&gt;&lt;PRE&gt;#!/bin/sh

SERVICE1=appnameA
BOX1=boxA.foobar.com
PORT1=5000

curl -s "http://$BOX1:$PORT1/segment/region/phase/dest?app=$SERVICE1" | grep DISABLED
if (`echo $?` eq 0 )
then 
mail -s "$SERVICE1 is down" allanm@foobar.com &amp;lt;/dev/null
fi&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Thanks,&lt;/P&gt;&lt;P&gt;Allan.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2011 21:59:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5310169#M641947</guid>
      <dc:creator>allanm77</dc:creator>
      <dc:date>2011-08-23T21:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Script help.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5310185#M641948</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.hpe.com/t5/user/viewprofilepage/user-id/1196371"&gt;@allanm77&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Created a piece of shell script, want to iterate the curl statement and if condition for multiple Services,boxes combination (within the same script) and send multiple emails if the condition is met.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If possible would prefer this to be converted to perl.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So, place a 'for' loop around the 'curl...if...fi' .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why do you feel the need to convert this to Perl?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2011 22:46:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5310185#M641948</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-08-23T22:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Script help.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5310193#M641949</link>
      <description>Thanks JRF!&lt;BR /&gt;&lt;BR /&gt;Its my never ending desire to compare how code works between shell and perl.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Allan.</description>
      <pubDate>Tue, 23 Aug 2011 22:59:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5310193#M641949</guid>
      <dc:creator>allanm77</dc:creator>
      <dc:date>2011-08-23T22:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Script help.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5310971#M641950</link>
      <description>&lt;P&gt;Hi (again) Allan:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How about evaulating the comments here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://h30499.www3.hp.com/t5/Languages-and-Scripting/How-to-fasten-nested-quot-for-quot-loops/td-p/5306443" target="_blank"&gt;http://h30499.www3.hp.com/t5/Languages-and-Scripting/How-to-fasten-nested-quot-for-quot-loops/td-p/5306443&lt;/A&gt;﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2011 12:32:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5310971#M641950</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-08-24T12:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: Script help.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5311279#M641951</link>
      <description>Hi JRF,&lt;BR /&gt;&lt;BR /&gt;Evaluated, thanks!&lt;BR /&gt;&lt;BR /&gt;Can you provide the perl equivalent of the shell script..&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Allan.</description>
      <pubDate>Wed, 24 Aug 2011 17:21:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5311279#M641951</guid>
      <dc:creator>allanm77</dc:creator>
      <dc:date>2011-08-24T17:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: Script help.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5311309#M641952</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.hpe.com/t5/user/viewprofilepage/user-id/1196371"&gt;@allanm77&lt;/a&gt; wrote:&lt;BR /&gt;Hi JRF,&lt;BR /&gt;Can you provide the perl equivalent of the shell script..&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;OK, here's one possibility.&amp;nbsp; I am going to assume that you have some knowledge of Perl and/or that you will dig with this as an example :-)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#!/usr/bin/perl
use strict;
use warnings;

my $SERVICE1 = q(appnameA);
my $BOX1     = q(boxA.foobar.com);
my $PORT1    = 5000;

my $result =
    qx(curl -s "http://$BOX1:$PORT1/segment/region/phase/dest?app=$SERVICE1");
my $rc = $?;&lt;BR /&gt;&lt;BR /&gt;die "Can't fetch URL; return code = ", +($rc &amp;gt;&amp;gt; 8), "\n" unless $rc == 0;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;if ( $result =~ m{DISABLED} ) {
    system qq( mail -s "$SERVICE1 is down" allanm\@foobar.com &amp;lt;/dev/null );
}
1;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2011 19:16:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5311309#M641952</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-08-24T19:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: Script help.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5311587#M641953</link>
      <description>&lt;P&gt;Thanks JRF!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One more issue I am thinking of is that we have more than 10 boxes in production and I need to do this on more than 5 apps so it would be wonderful if the solution is better than a for loop, maybe array?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Allan.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2011 22:07:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5311587#M641953</guid>
      <dc:creator>allanm77</dc:creator>
      <dc:date>2011-08-24T22:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Script help.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5311655#M641954</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.hpe.com/t5/user/viewprofilepage/user-id/1196371"&gt;@allanm77&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Thanks JRF!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One more issue I am thinking of is that we have more than 10 boxes in production and I need to do this on more than 5 apps so it would be wonderful if the solution is better than a for loop, maybe array?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I like the way your requests grow as I offer a solution for each iteration ;-)&amp;nbsp; Don't forget to evaluate each solution as we go along.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For this last one, we will use a hash for several reasons.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#!/usr/bin/perl
use strict;
use warnings;

my %apps = (
    appnameA =&amp;gt; q(boxA.foobar.com),
    appnameB =&amp;gt; q(boxB.foobar.com),
    appnameC =&amp;gt; q(boxC.foobar.com),
);
    
my $port = 5000;

while ( my ( $service, $box ) = each %apps ) {
    my $url    = qq(http://$box:$port/segment/region/phase/dest?app=$service);
    my $result = qx(curl -s $url);
    my $rc     = $?;

    die "Can't fetch $url; return code = ", +($rc &amp;gt;&amp;gt; 8), "\n" unless $rc == 0;

    if ( $result =~ m{DISABLED} ) {
        system qq
            ( mail -s "$service down on $box" allanm\@foobar.com &amp;lt;/dev/null );
    }
}
1;&lt;/PRE&gt;&lt;P&gt;Notice, among other things, that I have lower-cased the variable names.&amp;nbsp; Upper-case names are generally used for constants.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can add more items to the hash as necessary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2011 01:55:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5311655#M641954</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-08-25T01:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Script help.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5312187#M641955</link>
      <description>&lt;P&gt;Hi (again):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Oops, we really don't want to die() and abandon all processing when we loop through the hash and curl() returns a non-zero value.&amp;nbsp; Instead, replace this line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;die "Can't fetch $url; return code = ", +($rc &amp;gt;&amp;gt; 8), "\n" unless $rc == 0;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;...with this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if ( $rc != 0 ) {
    warn "Can't fetch $url; return code = ", +($rc &amp;gt;&amp;gt; 8), "\n";
    next;
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;This reports the error and continues to process the next hash member.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2011 12:07:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5312187#M641955</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-08-25T12:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Script help.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5312601#M641956</link>
      <description>Thanks JRF!</description>
      <pubDate>Thu, 25 Aug 2011 18:21:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5312601#M641956</guid>
      <dc:creator>allanm77</dc:creator>
      <dc:date>2011-08-25T18:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: Script help.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5313813#M641957</link>
      <description>&lt;P&gt;Why use external commands if perl supports this though modules extremely well?&lt;/P&gt;&lt;PRE&gt;#!/usr/bin/perl

use strict;
use warnings;
use LWP;
use LWP::UserAgent;
use Mail::Sendmail;

my %apps = (
    appnameA =&amp;gt; "boxA.foobar.com",
    appnameB =&amp;gt; "boxB.foobar.com",
    appnameC =&amp;gt; "boxC.foobar.com",
    );
my $port = 5000;
my $ua = LWP::UserAgent-&amp;gt;new (
    agent      =&amp;gt; "Opera/11.00 opera 11",
    cookie_jar =&amp;gt; {},
    );

while (my ($service, $box) = each %apps) {
    my $url = qq(http://$box:$port/segment/region/phase/dest?app=$service);
    my $rsp = $ua-&amp;gt;request (HTTP::Request-&amp;gt;new (GET =&amp;gt; $url));

    $rsp-&amp;gt;is_success or die "get failed: ", $rsp-&amp;gt;status_line, "\n";
    if ($rsp-&amp;gt;content =~ m/DISABLED/) {
        sendmail (
            To      =&amp;gt; 'allanm@foobar.com',
            From    =&amp;gt; 'me@this.box',
            Subject =&amp;gt; "$service down on $box",
            Message =&amp;gt; "Please fix",
            ) or die $Mail::Sendmail::error;
        }
    }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2011 19:34:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5313813#M641957</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2011-08-26T19:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Script help.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5314405#M641958</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.hpe.com/t5/user/viewprofilepage/user-id/862084"&gt;@H.Merijn Brand&lt;/a&gt; (procura wrote:&lt;BR /&gt;&lt;P&gt;Why use external commands if perl supports this though modules extremely well?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I agree, particularly from a portability standpoint. &amp;nbsp; Of course, Allan is probably running Perl 5.8.8 from the standard HP-UX distributions.&amp;nbsp; He would need to install the LWP::UserAgent (perhaps) and Mail::SendMail from CPAN.&amp;nbsp; While this is trivial, some sites are reticent in these regards :-(&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
      <pubDate>Sun, 28 Aug 2011 13:48:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5314405#M641958</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-08-28T13:48:53Z</dc:date>
    </item>
  </channel>
</rss>

