- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl 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
Forums
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
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-12-2010 08:37 PM
08-12-2010 08:37 PM
I created a Perl script to do a wget on an URL.
Script's output is like the following -
{
"_exp" = "81652254";
"apps" = {
"AcctInfoapps" = "http://spaceqa3-svc.corp.zaphida.com:7322/cgi-bin/jboss/OrderManagementapps-MEA.joa/accountInfo";
"StatContentapps" = "http://egq3-wsf-5001.corp.zaphida.com:8531/service/staticcontent";
"ContappsB2B" = "http://spaceqa3-svc.corp.zaphida.com:9203/jboss/apps.joa/content";
"CommQandAStatisticapps" = "http://spaceqa3-svc.corp.zaphida.com:8546/service/qastats";
"SerialNberapps" = "http://spaceqa3-svc.corp.zaphida.com:8341/jboss/apps.joa/serial";
};
}
What I need is the following -
1)is to store the output to an array and parse out http://...:port (e.g. -
http://spaceqa3-svc.corp.zaphida.com:8341/)
and the appname (e.g. SerialNberapps )
and store in scalar.
2)Then append the uri cgi-bin/jboss/apps.joa/health?method=checkurl to each of the urls (from 1)
3) echo appname and again run wget against each url from 2.
Here is the script that I created -
#!/usr/bin/perl -w
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->agent("Mozilla/8.0");
$req = HTTP::Request->new(GET => 'http://apps.zaphida.com:8501/jboss/Service.woa/mea?method=getServices');
$req->header('Accept' => 'text');
$res = $ua->request($req);
if ($res->is_success) {
print $res->decoded_content;
}
else {
print "Error: ". $res->status_line."\n";
}
Solved! Go to Solution.
- Tags:
- wget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2010 05:30 AM
08-13-2010 05:30 AM
Re: Perl Help
See if this snippet guides you:
# cat ./fetch
#!/usr/bin/perl
use strict;
use warnings;
{
$/ = undef;
my $str = ;
$str =~ m{SerialNberapps".+"(.+)"} and print $1, "\n";
}
__DATA__
{
"_exp" = "81652254";
"apps" = {
"AcctInfoapps" = "http://spaceqa3-svc.corp.zaphida.com:7322/cgi-bin/jboss/OrderManagementapps-MEA.joa/accountInfo";
"StatContentapps" = "http://egq3-wsf-5001.corp.zaphida.com:8531/service/staticcontent";
"ContappsB2B" = "http://spaceqa3-svc.corp.zaphida.com:9203/jboss/apps.joa/content";
"CommQandAStatisticapps" = "http://spaceqa3-svc.corp.zaphida.com:8546/service/qastats";
"SerialNberapps" = "http://spaceqa3-svc.corp.zaphida.com:8341/jboss/apps.joa/serial";
};
}
# ./fetch
http://spaceqa3-svc.corp.zaphida.com:8341/jboss/apps.joa/serial
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2010 09:20 AM
08-13-2010 09:20 AM
Re: Perl Help
The string matching is a problem cause I can have 50+ appnames in the the output and I need a non hard code way of parsing out the http://...:port and appname.
Also once I have the http://...:port URL I want to append a certain uri to the URLs (http://....port ) and echo appname and run a wget against each one of the appended URL so as to check their health.
The output would be something like this
Appname1
Status - OK
Appname2
Status - WARN
Thanks,
Allanm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2010 09:40 AM
08-13-2010 09:40 AM
Re: Perl Help
> The string matching is a problem cause I can have 50+ appnames in the the output and I need a non hard code way of parsing out the http://...:port and appname.
Then consider this prototype:
# cat ./fetch
#!/usr/bin/perl
use strict;
use warnings;
{
$/ = undef;
my $str = ;
my @names = ( $str =~ m{SerialNberapps".+"(.+)"}g );
print "$_\n" for @names;
}
__DATA__
{
"_exp" = "81652254";
"apps" = {
"AcctInfoapps" = "http://spaceqa3-svc.corp.zaphida.com:7322/cgi-bin/jboss/OrderManagementapps-MEA.joa/accountInfo";
"StatContentapps" = "http://egq3-wsf-5001.corp.zaphida.com:8531/service/staticcontent";
"ContappsB2B" = "http://spaceqa3-svc.corp.zaphida.com:9203/jboss/apps.joa/content";
"CommQandAStatisticapps" = "http://spaceqa3-svc.corp.zaphida.com:8546/service/qastats";
"SerialNberapps" = "http://spaceqa3-svc.corp.zaphida.com:8341/jboss/apps.joa/serial";
};
}
{
"_exp" = "81652254";
"apps" = {
"AcctInfoapps" = "http://spaceqa3-svc.corp.zaphida.com:7322/cgi-bin/jboss/OrderManagementapps-MEA.joa/accountInfo";
"StatContentapps" = "http://egq3-wsf-5001.corp.zaphida.com:8531/service/staticcontent";
"ContappsB2B" = "http://spaceqa3-svc.corp.zaphida.com:9203/jboss/apps.joa/content";
"CommQandAStatisticapps" = "http://spaceqa3-svc.corp.zaphida.com:8546/service/qastats";
"SerialNberapps" = "http://spaceqa4-svc.corp.zaphida.com:8341/jboss/apps.joa/serial";
};
}
{
"_exp" = "81652254";
"apps" = {
"AcctInfoapps" = "http://spaceqa3-svc.corp.zaphida.com:7322/cgi-bin/jboss/OrderManagementapps-MEA.joa/accountInfo";
"StatContentapps" = "http://egq3-wsf-5001.corp.zaphida.com:8531/service/staticcontent";
"ContappsB2B" = "http://spaceqa3-svc.corp.zaphida.com:9203/jboss/apps.joa/content";
"CommQandAStatisticapps" = "http://spaceqa3-svc.corp.zaphida.com:8546/service/qastats";
"SerialNberapps" = "http://spaceqa5-svc.corp.zaphida.com:8341/jboss/apps.joa/serial";
};
}
...thus:
# ./fetch
http://spaceqa3-svc.corp.zaphida.com:8341/jboss/apps.joa/serial
http://spaceqa4-svc.corp.zaphida.com:8341/jboss/apps.joa/serial
http://spaceqa5-svc.corp.zaphida.com:8341/jboss/apps.joa/serial
...which collects all matches into an array whose elements are then printed for demonstration.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2010 10:31 AM
08-13-2010 10:31 AM
Re: Perl Help
Maybe I'm being too obtuse. Your wrote:
> ... store the output to an array and parse out http://...:port (e.g. -
http://spaceqa3-svc.corp.zaphida.com:8341/)
and the appname (e.g. SerialNberapps )
and store in scalar.
Given that $res->decoded_content has the output you could do:
# push @names, $1 if $res->decoded_context =~ m{SerialNberapps".+"(.+)"};
...to collect the "appname" URLs into an array.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2010 02:00 PM
08-13-2010 02:00 PM
Re: Perl Help
AcctInfoapps, StatContentapps ....
Is there a way to get those? More like a generic way to loop through them in an array/hash?
Sorry if I may not have been clear earlier...
Thanks,
Allan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2010 04:00 PM
08-13-2010 04:00 PM
Solution> The string matching just gets me SerialNberapps but not the other apps like
AcctInfoapps, StatContentapps ....
Yes:
# cat ./fetch
#!/usr/bin/perl
use strict;
use warnings;
my $res;
my @names;
while ( $res = ) {
push @names, ( $res =~ m{^".+apps.*"\s*=\s*"(.+)"} );
}
print "$_\n" for @names;
__DATA__
{
"_exp" = "81652254";
"apps" = {
"AcctInfoapps" = "http://spaceqa3-svc.corp.zaphida.com:7322/cgi-bin/jboss/OrderManagementapps-MEA.joa/accountInfo";
"StatContentapps" = "http://egq3-wsf-5001.corp.zaphida.com:8531/service/staticcontent";
"ContappsB2B" = "http://spaceqa3-svc.corp.zaphida.com:9203/jboss/apps.joa/content";
"CommQandAStatisticapps" = "http://spaceqa3-svc.corp.zaphida.com:8546/service/qastats";
"SerialNberapps" = "http://spaceqa3-svc.corp.zaphida.com:8341/jboss/apps.joa/serial";
};
}
# ./fetch
http://spaceqa3-svc.corp.zaphida.com:7322/cgi-bin/jboss/OrderManagementapps-MEA.joa/accountInfo
http://egq3-wsf-5001.corp.zaphida.com:8531/service/staticcontent
http://spaceqa3-svc.corp.zaphida.com:9203/jboss/apps.joa/content
http://spaceqa3-svc.corp.zaphida.com:8546/service/qastats
http://spaceqa3-svc.corp.zaphida.com:8341/jboss/apps.joa/serial
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2010 04:47 PM
08-16-2010 04:47 PM
Re: Perl Help
that was simply awesome...
Two things I need to discuss further on this -
1) push @names, ( $res =~ m{^".+apps.*"\s*=\s*"(.+)"} );
The above string, shouldn't it produce
"AcctInfoapps" = "http://spaceqa3-svc.corp.zaphida.com:7322/cgi-bin/jboss/OrderManagementapps-MEA.joa/accountInfo"
but produces just the url... want to understand how?
One more thing I want to do is to append a URI to the URL that I got from above -
2)Then append the uri cgi-bin/jboss/apps.joa/health?method=checkurl to each of the urls (from 1) and run wget against each URL.
Can you address these two things as well?
Thanks so much!
Allan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2010 08:40 AM
08-17-2010 08:40 AM
Re: Perl Help
Can you please answer my above questions.
Thanks,
Allan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2010 12:36 PM
08-17-2010 12:36 PM
Re: Perl Help
I was expecting result in the following format -
./fetch.pl
http://spaceqa3-svc.corp.zaphida.com:7322/cgi-bin/jboss/apps.joa/health?method=checkurl
http://egq3-wsf-5001.corp.zaphida.com:8531/cgi-bin/jboss/apps.joa/health?method=checkurl
http://spaceqa3-svc.corp.zaphida.com:9203/cgi-bin/jboss/apps.joa/health?method=checkurl
http://spaceqa3-svc.corp.zaphida.com:8546/cgi-bin/jboss/apps.joahealth?method=checkurl
http://spaceqa3-svc.corp.zaphida.com:8341/cgi-bin/jboss/apps.joa/health?method=checkurl
I need the output to be stored in a data structure so I can run LWP/wget against each URL and get the health status output.
Sorry I am still learning perl and need to get a hang of it.
Your help is most appreciated.
Thanks,
Allan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2010 01:59 PM
08-20-2010 01:59 PM
Re: Perl Help
# cat ./fetch
#!/usr/bin/perl
use strict;
use warnings;
my $uri = q(cgi-bin/jboss/apps.joa/health?method=checkurl);
my $res;
my @names;
while ( $res = ) {
push @names, $res =~ m{^".+apps.*"\s*=\s*"(.+:\d+/)};
}
for (@names) {
my $wget = $_ . $uri;
print "$wget\n";
}
__DATA__
{
"_exp" = "81652254";
"apps" = {
"AcctInfoapps" = "http://spaceqa3-svc.corp.zaphida.com:7322/cgi-bin/jboss/OrderManagementapps-MEA.joa/accountInfo";
"StatContentapps" = "http://egq3-wsf-5001.corp.zaphida.com:8531/service/staticcontent";
"ContappsB2B" = "http://spaceqa3-svc.corp.zaphida.com:9203/jboss/apps.joa/content";
"CommQandAStatisticapps" = "http://spaceqa3-svc.corp.zaphida.com:8546/service/qastats";
"SerialNberapps" = "http://spaceqa3-svc.corp.zaphida.com:8341/jboss/apps.joa/serial";
};
}
# ./fetch
http://spaceqa3-svc.corp.zaphida.com:7322/cgi-bin/jboss/apps.joa/health?method=checkurl
http://egq3-wsf-5001.corp.zaphida.com:8531/cgi-bin/jboss/apps.joa/health?method=checkurl
http://spaceqa3-svc.corp.zaphida.com:9203/cgi-bin/jboss/apps.joa/health?method=checkurl
http://spaceqa3-svc.corp.zaphida.com:8546/cgi-bin/jboss/apps.joa/health?method=checkurl
http://spaceqa3-svc.corp.zaphida.com:8341/cgi-bin/jboss/apps.joa/health?method=checkurl
...the regular expression matches the URL that begins a line (^) with a double quote; followed by one or more characters (.+); the sequence "apps"; zero or more characters (.*); a double quote; optional whitespace (\s*); an equal sign; some more optional whitespace; and a double quote. The next sequence in parentheses is captured in a variable named $1. We look for one or more characters; a colon; one or more digits; and a forward slash. This is the URL we will stuff into our array.
m{^".+apps.*"\s*=\s*"(.+:\d+/)};
Having loaded an array with the URLs we want, we can loop through that array and concatenate (that's the dot operator) the URI you want to form a new variable to pass to a wget().
If you like, you could extract the URL and concatenate before stuffing your array variable, or simply extract and concatenate into a variable that you immediately use with wget().
Regards!
...JRF...