-
-
Save t1m0thyj/f748e1d87f1c7cc34b32655dd4ad5ac6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* REXX */ | |
SAY '{' | |
SAY ' "anArray": ' | |
SAY ' [' | |
DO i = 0 TO 9999 BY 1 | |
SAY ' {' | |
SAY ' "element'i'": "value'i'" ' | |
IF (i+1 < 10000) THEN | |
DO | |
SAY ' },' | |
END | |
ELSE | |
DO | |
SAY ' }' | |
END | |
END | |
SAY ' ]' | |
SAY '}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -ex | |
CURL_ARGS="--insecure" | |
PY3=python | |
TSO_CMD="exec 'XXX.PUBLIC.REXX(JSONTEST)'" | |
TSO_PARMS="proc=IZUFPROC&chset=697&cpage=1047&rows=24&cols=80&acct=IZUACCT&rsize=4096" | |
ZOSMF_HOST=example.com | |
ZOSMF_PORT=443 | |
ZOSMF_USER=XXX # Change me | |
# Clean up files from previous run | |
rm out.json response*.json || true | |
# Get LTPA token from z/OSMF | |
curl $CURL_ARGS -X POST --user $ZOSMF_USER --cookie-jar cookies.txt \ | |
"https://${ZOSMF_HOST}:${ZOSMF_PORT}/zosmf/services/authenticate" \ | |
-H 'Content-Type: application/x-www-form-urlencoded' \ | |
-H 'X-CSRF-ZOSMF-HEADER;' | |
# Start TSO session | |
curl $CURL_ARGS -X POST -b cookies.txt \ | |
"https://${ZOSMF_HOST}:${ZOSMF_PORT}/zosmf/tsoApp/tso?${TSO_PARMS}" \ | |
-H 'Content-Type: application/json' \ | |
-H 'X-CSRF-ZOSMF-HEADER;' > initial.txt | |
# Obtain servlet key for TSO session | |
servletKey=$(cat initial.txt | $PY3 -c "import json, sys; print(json.loads(sys.stdin.read())['servletKey'])") | |
echo "servletKey=${servletKey}" | |
# Python script that extracts TSO data | |
pyParseScript="import json, sys | |
with open(sys.argv[1]) as json_file: | |
data = json.load(json_file) | |
for element in data['tsoData']: | |
if 'TSO MESSAGE' in element: | |
msg = element['TSO MESSAGE'] | |
theData = msg['DATA'] | |
if 'READY' not in theData: | |
print(theData)" | |
# Execute TSO command | |
curl $CURL_ARGS -X PUT -b cookies.txt \ | |
"https://${ZOSMF_HOST}:${ZOSMF_PORT}/zosmf/tsoApp/tso/${servletKey}?readReply=true" \ | |
-H 'Content-Type: application/json' \ | |
-H 'X-CSRF-ZOSMF-HEADER;' \ | |
-d "{\"TSO RESPONSE\":{\"VERSION\":\"0100\",\"DATA\":\"${TSO_CMD}\"}}" > response0.json | |
$PY3 -c "$pyParseScript" response0.json >> out.json | |
# Retrieve output from TSO command | |
i=0 | |
while : ; do | |
((i=i+1)) | |
curl $CURL_ARGS -X GET -b cookies.txt \ | |
"https://${ZOSMF_HOST}:${ZOSMF_PORT}/zosmf/tsoApp/tso/${servletKey}" \ | |
-H 'Content-Type: application/json' \ | |
-H 'X-CSRF-ZOSMF-HEADER;' > response$i.json | |
if grep -q '"timeout":true' response$i.json; then break; fi | |
$PY3 -c "$pyParseScript" response$i.json >> out.json | |
done | |
# Stop TSO session | |
curl $CURL_ARGS -X DELETE -b cookies.txt \ | |
"https://${ZOSMF_HOST}:${ZOSMF_PORT}/zosmf/tsoApp/tso/${servletKey}" \ | |
-H 'Content-Type: application/json' \ | |
-H 'X-CSRF-ZOSMF-HEADER;' | |
# Check that command output is valid JSON | |
$PY3 -m json.tool out.json > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment