OPS/REXX: Calling cURL, Python, & JavaScript

Dan Kelosky
3 min readSep 15, 2023

OPS/REXX is a scripting language that can be used to automate many operations on z/OS. Recently, OPS/REXX users have been interested in extending their automation to make use of other tools and services, such as cURL, Python, and JavaScript (via Node.js). Below, we’ll show examples for each of these using the ADDRESS USS commands in OPS/REXX.

Note — see the ENVFILE mention in the ADDRESS USS doc (mentioned above) to set your PATH if you get FSUM7351 not found when invoke USS commands.

cURL

cURL is a command line tool that allows you to quickly make calls over HTTP. If this tool is available on your workstation, you can invoke it from your terminal (e.g. Windows Command Prompt). For example, this command calls a free public, fake API that can be used for testing:

curl -k https://jsonplaceholder.typicode.com/posts/1 2>/dev/null

Command response from cURL

You can call this same cURL command via OPS/REXX with a little bit of code:

Running this OPS/REXX with !OI gives this result:

Invoking cURL on z/OS via an OPS/REXX script to call a public REST API

This example shows a quick way to call a REST API via OPS/REXX.

Python

Python is the 3rd most commonly-used language among developers. You can invoke python scripts using the same technique used to run cURL, that is, using ADDRESS USS.

Here’s an overview of the upcoming example:

  1. We’ll use some OPS/REXX to obtain system information via built-in functions
  2. The OPS/REXX then invokes a python script, script.py, passing along the system information that was just obtained
  3. The python script runs and echoes out the system information obtained via build-in functions (with some basic parsing)
  4. Lastly, OPS/REXX emits the output produced by the python script

OPS/REXX:

OPS/REXX to obtain system info, run a python script, and echo script output

script.py:

import sys

# echo input arguments
print(
f"sysname: {sys.argv[1]}\nz/os version: {sys.argv[2]}\nops version: {sys.argv[3]}\nosf servers: {sys.argv[9]}")

Upon running via !OI:

Python script output invoked via OPS/REXX

The output produce from opsprm is OSF MINIMUM ACTIVE SERVER COUNT 1 SERVERS. Although it’s trivial to parse strings in REXX, using this technique, we’re setup to perform parsing and presentation via the python programming language.

JavaScript (via Node.js)

JavaScript is the most used language and can be executed in a browser context or in a similar fashion to python via Node.js.

Similar to the cURL example, we’ll write JavaScript to call a public REST API on z/OS. Then, we’ll copy the output to a z/OS data set using a cp command:

import { writeFileSync } from "fs"
import { execSync } from "child_process"
import { request } from "https";

// call a public REST API
const req = request("https://jsonplaceholder.typicode.com/posts/1", (res) => {

let buffer = '';

res.on('data', (data) => {
buffer += data;
});

res.on('end', () => {
// place output in a file and copy to z/OS data set
writeFileSync("/tmp/kelda16/out.txt", buffer.toString().replace(/(.{72})/g, "$1\n"), "cp1047");
execSync(`cp -P "recfm=fb,lrecl=80,space=(10,10)" /tmp/kelda16/out.txt "//'opsmvs.nodedata'"`);
});

});

req.end();

We can execute this JavaScript via a minimal ammount of OPS/REXX:

ADDRESS USS                         
"USSCMD COMMAND('",
"NODE_SMF89_SUPPRESS_WARNING=true",
"node /tmp/script.mjs",
"') ",
"STEM(RESPONSE)"

Lastly, when we run this with !OI we can see the output in a z/OS data set OPSMVS.NODEDATA:

OPS/REXX calls JavaScript to invoke a public REST API and places this output in a z/OS data set

Summary

Running z/OS Unix commands from OPS/REXX allows you to do much more than simply invoking cURL, python, and JavaScript as described above. Although the examples given are contrived, you can extend these examples for our own use case or to invoke other tools too!

Bonus tip: when building/editing OPS/REXX, try the VS Code extension support for it!

--

--

Dan Kelosky

Likes programming/automation in mainframe (assembler, C/C++), distributed (Node.js), and web development (Firebase, Angular).