1752290 Members
5070 Online
108786 Solutions
New Discussion юеВ

Re: Script help!

 
SOLVED
Go to solution
Allanm
Super Advisor

Script help!

Hi All,

I have the following curl command out of which I want to get two values in two separate variables -

curl -w '\ntotal_time=%{time_total}s' -s http://zap.com:9999/cgi-bin/jboss/service.java/check?method=ping

THE OUTPUT -

{
"alive" = "ping";
"exp" = "-1";
"request" = {
"method" = "ping";
};
}
total_time=0.506s

VAR1 - I want to capture the word "alive" and if its present in the output then print "OK" and if not present or timed out print "ERROR"

VAR2 - I want to capture the string "total_time=0.506s" as is in variable 2.

I am able to do this by two separate invocations of curl but can this be done in a single invocation of curl without saving the output to a file?

Thanks,
Allan.






3 REPLIES 3
Horia Chirculescu
Honored Contributor

Re: Script help!

Hello,

"I am able to do this by two separate invocations of curl but can this be done in a single invocation of curl without saving the output to a file?"

You could use pipe (|) to avoid saving the output of the first curl to a file.

Horia.
Best regards from Romania,
Horia.
James R. Ferguson
Acclaimed Contributor
Solution

Re: Script help!

Hi Allan:

Perhaps:

# curl -w ... | perl -n0e '$v1=/"alive"/?"OK":"ERROR";($v2)=/(total_time.+)/;print "$v1 $v2\n"'

...which using your output would have produced:

OK total_time=0.506s

Regards!

...JRF...
Allanm
Super Advisor

Re: Script help!

thanks JRF!