Shell or perl script needed

Hi!

I have a curl call which gets me the following output:

curl http://hostname1.qa.com:8888/getlist

OUTPUT -

{
"token" = "201119041112";
"apps" = {
"PaymentApp" = "http://hostname1.qa.com:2333/cgi-bin/Jboss/PaymentApp-EMEA.woa/paymentInfo";
"OrderConsumer" = "http://hostname.qa2.com:2345/apps/orders";
...
};
}

Based on the curl call which is being made to a specific URL , I need to parse out URL entries which are of similar pattern as the URL to which the call was made (http://hostname1.qa.com) -

I need to scrub out only entries which have hostname1 in them.

Then I need to populate a couple of properties files which look like this with the appname (e.g. PaymentApp) , URL(http://hostname1.qa.com:2333), host(hostname1.qa.com) , port(e.g. 2333) , env (e.g. qa) information that I gathered from above -

file1 -

define service{
host_name $hostname
use generic-service
servicegroups preprod apps
service_description $appname
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
contact_groups admin
notification_interval 120
notification_period 24x7
notification_options w,u,c,r
process_perf_data 0
check_command url-check_$env_$port
}

file2 -

define command{
command_name url-check_$env_$port
command_line $USER1$/url-check -H $hostname -p $port -r added --regex=alive -t 4
}

The initial curl call can be part of the script itself.

Thanks,
Jack.

Anything you tried yourself yet?

Hi All!

Here is what I have currently -

curl http://host.domain.com:8000/Jboss/Service.jbs/america?method=geturls|grep host.domain.com |awk '{print $1,$3}'

"OrderApp" "http://host.domain.com:8100/apps/Orderinfo";
"EmailAppTest" "http://host.domain.com:5100/apps/email";
...
...

I need to strip out the following words -

OrderApp host.domain.com 8100
EmailAppTest host.domain.com 5100
...
...

So appname , host & port from above.
Then once I have that I can echo that to generate properties files through a while loop.

Thanks,
Jack.

See if this can help your output:

sed 's/"\(.*\)" ".*:..\(.*\):\(....\)\/.*/\1 \2 \3/' 
1 Like

Thanks Shell_life, can you explain a little abt this regex?

-Jack.