- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script help.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2011 02:59 PM
08-23-2011 02:59 PM
Hi All,
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.
If possible would prefer this to be converted to perl.
#!/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 </dev/null fi
Thanks,
Allan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2011 03:46 PM
08-23-2011 03:46 PM
Re: Script help.
@allanm77 wrote:Hi All,
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.
If possible would prefer this to be converted to perl.
So, place a 'for' loop around the 'curl...if...fi' .
Why do you feel the need to convert this to Perl?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2011 03:59 PM
08-23-2011 03:59 PM
Re: Script help.
Its my never ending desire to compare how code works between shell and perl.
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2011 05:32 AM
08-24-2011 05:32 AM
Re: Script help.
Hi (again) Allan:
How about evaulating the comments here?
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2011 10:21 AM
08-24-2011 10:21 AM
Re: Script help.
Evaluated, thanks!
Can you provide the perl equivalent of the shell script..
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2011 11:04 AM - edited 08-24-2011 12:16 PM
08-24-2011 11:04 AM - edited 08-24-2011 12:16 PM
Re: Script help.
@allanm77 wrote:
Hi JRF,
Can you provide the perl equivalent of the shell script..
OK, here's one possibility. I am going to assume that you have some knowledge of Perl and/or that you will dig with this as an example :-)
#!/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 = $?;
die "Can't fetch URL; return code = ", +($rc >> 8), "\n" unless $rc == 0;
if ( $result =~ m{DISABLED} ) { system qq( mail -s "$SERVICE1 is down" allanm\@foobar.com </dev/null ); } 1;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2011 03:07 PM
08-24-2011 03:07 PM
Re: Script help.
Thanks JRF!
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?
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2011 05:30 PM - edited 08-24-2011 06:55 PM
08-24-2011 05:30 PM - edited 08-24-2011 06:55 PM
Re: Script help.
@allanm77 wrote:Thanks JRF!
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?
I like the way your requests grow as I offer a solution for each iteration ;-) Don't forget to evaluate each solution as we go along.
For this last one, we will use a hash for several reasons.
#!/usr/bin/perl use strict; use warnings; my %apps = ( appnameA => q(boxA.foobar.com), appnameB => q(boxB.foobar.com), appnameC => 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 >> 8), "\n" unless $rc == 0; if ( $result =~ m{DISABLED} ) { system qq ( mail -s "$service down on $box" allanm\@foobar.com </dev/null ); } } 1;
Notice, among other things, that I have lower-cased the variable names. Upper-case names are generally used for constants.
You can add more items to the hash as necessary.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2011 05:07 AM
08-25-2011 05:07 AM
SolutionHi (again):
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. Instead, replace this line:
die "Can't fetch $url; return code = ", +($rc >> 8), "\n" unless $rc == 0;
...with this:
if ( $rc != 0 ) { warn "Can't fetch $url; return code = ", +($rc >> 8), "\n"; next; }
This reports the error and continues to process the next hash member.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2011 11:21 AM
08-25-2011 11:21 AM