Streamline your mainframe development with Zowe Explorer & Zowe CLI (a series)— Part 1: z/OS Unix shell scripting
{Core}
Since Open Mainframe Project’s Zowe came to light, development on z/OS Unix became much easier for me, in the sense that I can use VS Code and the Zowe Explorer extension to access my z/OS Unix file system, edit and save a file from a single place. This is not to say that all of this can’t be done in ISPF, but VS Code provides a modern and flexible solution for me.
That being said, there is one elementary piece that I am missing, and that is, to run the script on the remote system and check the output.
Zowe CLI and VS Code tasks come to mind, as to one of the most organic solutions.
The general idea is to have the following steps automated in one task and run it from a shortcut:
- obtain the remote path of the file I am working with
- use BPXBATCH to run the said file
- download all spool files locally for reference
- parse the output and present a meaningful message in the console
I am running on Windows as my main OS, so I will go forward with a Powershell example. All the logic should be transferable to a bash script (I might even provide one later on) if you want to be platform-agnostic, although you will have to go through a little bit of work to set up git bash or Windows Subsystem for Linux to run bash scripts on your Windows machine.
Also, I am assuming you are already conformable using VS Code, Zowe Explorer, and Zowe CLI to work with your z/OS files.
Let’s take a closer look at the implementation:
- I am creating a new task in VS Code by opening the command palette and going to
Tasks: Open User Tasks
. There I am adding a new task, which I will callRun USS script
. There is the possibility to run a CLI command directly, but I am opting to run a Powershell script. This gives me more flexibility in terms of templating the JCL I am planning to submit and also for post-processing the results. You can also choose to have optional inputs when you run your task. I have included a drop-down list and a prompt for reference. The values provided here will be passed to the script.
- I am creating a Powershell script that takes some arguments. In my case, the local file path (mandatory) and an optional one specifying the profile you want to use with Zowe CLI.
- You might notice two things that are not provided yet. First is the module imported at the top of the file and the second is the
params.json
file. I’ve done it like so, to achieve a better structure in the script. These two are as follows:
- this needs to be present next to the Powershell script. Otherwise, you might want to check out the official documentation to place it in the default location pointed out by the
PSModulePath
environment variable if you want to import it as any other Powershell module.
- for the
params.json
file, I have chosen to structure it this way, because I want to use it with more scripts. You can choose to split it in separate files, or as you see fit. You might have noticed that importing this in Powershell is very easy, and accessing the parameters is equally convenient using the dot notation. - Some parameters explained:
keepSpool (boolean)= choose if you want to keep the downloaded spool files or not
defaultStdout (string) = path to STDOUT spool file (can vary based on submitted job)
defaultProfile (string) = if not passed from the task, this Zowe CLI profile will be used
outputJcl (string) = file name where the script will write the templated JCL before submitting
jobCard (object) = holds parameters relevant to parameterize your JCL job card - (optional, but recommended) Bind the task to a keyboard key combo. In order to do that, I am going to the command palette and look for
Preferences: Open Keyboard Shortcuts (JSON)
. In there, I am adding the entry forRun USS script
(please tailor your combo to your needs and current mapping):
key
: add your own combocommand
: leave unchanged, because it points to VS Code tasksargs
: has to be the name of your task (seelabel
parameter in your task definition)
And I am done. Now whenever I edit a shell script in z/OS Unix, I only have to press CTRL+Y
to run it on a remote system and get the output in my local VS Code console. How cool is that?
End Result:
If you enjoyed this blog checkout more Zowe blogs here. Or, ask a question and join the conversation on the Open Mainframe Project Slack Channel #Zowe-dev, #Zowe-user or #Zowe-onboarding. If this is your first time using the OMP slack channel register here.
This blog is part 1 of “Streamline your mainframe development with Zowe Explorer & Zowe CLI (a series)”.
Full list:
- Part 1: z/OS Unix shell scripting
- Part 2: COBOL basics