Issue a lengthy cURL command via ADDRESS USS USSCMD
search cancel

Issue a lengthy cURL command via ADDRESS USS USSCMD

book

Article ID: 268329

calendar_today

Updated On:

Products

OPS/MVS Event Management & Automation

Issue/Introduction

How can a lengthy cURL command be formatted properly in an ADDRESS USS USSCMD statement spanning multiple lines in a REXX exec?

Example command:

curl -v -X POST -H "Content-Type: application/json" -H "Authorization: Bearer cd8fc0826a369fc86de95c362" https://some.url.address/something/something/something/something/else -d "{\"app_key\": \"1cf3407d29ab234f9456cde123\" \"status\":\"critical\" \"host\":\"BEDROCK\" \"check\":\"THE FLINTSTONES\"}"      

Attempting to handle the single quotes, double quotes and curly braces across multiple line continuations in the REXX code is problematic and causes various errors in the formatting of the cURL command being passed to USS. 

Environment

Release : 14.0

Resolution

The recommendation for this scenario is executing a pre-defined script file containing the cURL command on the USS side rather than attempting to issue the entire cURL command directly from the ADDRESS USS USSCMD statement. This removes the necessity of trying to format the single quotes, double quotes and curly braces across line continuations within the REXX code.

Example script file residing in a USS directory:

curl -v -X POST -H "Content-Type: application/json" -H "Authorization: Bearer cd8fc0826a369fc86de95c" \          
https://some.url.address/something/something/something/something/else \                                  
-d "{\"app_key\": \"1cf3407d29ab234f9456cde123\" \"status\":\"critical\" \"host\":\"BEDROCK\" \"check\":\"THE FLINTSTONES\"}
"      

In the above example, the backslash by itself at the end of the first two lines acts as a continuation character.

If the name of the script file above is "curlcmd", then it can be executed from an ADDRESS USS USSCMD statement as follows:

address uss "USSCMD COMMAND('/uss_directory_path/curlcmd')"

where "uss_directory_path" is the directory that the curlcmd script resides in.

Parameters can also be passed to the script file if necessary:

address uss "USSCMD COMMAND('/uss_directory_path/curlcmd critical BEDROCK THE FLINTSTONES')"

The parameters are substituted into the scrip file with the use of variables $1 $2...$n in the script:

curl -v -X POST -H "Content-Type: application/json" -H "Authorization: Bearer cd8fc0826a369fc86de95c" \          
https://some.url.address/something/something/something/something/else \                                  
-d "{\"app_key\": \"1cf3407d29ab234f9456cde123\" \"status\":\"$1\" \"host\":\"$2\" \"check\":\"$3 $4\"}
"