How to Invoke USS from z/OS Batch Jobs

In order to run Unix System Services (USS) shell commands, scripts and others, from a batch job, you can use the BPXBATCH program provided with z/OS.

BPXBATCH can be invoked form a JCL (batch job) or from TSO:

  • JCL:
    • EXEC PGM=BPXBATCH,PARM=’SH program-name’
    • EXEC PGM=BPXBATCH,PARM=’PGM program-name’
  • TSO:
    • BPXBATCH SH program-name
    • BPXBATCH PGM program-name

BPXBATCH allows you to allocate the z/OS standard files stdin, stdout, and stderr as z/OS UNIX files for passing input, for shell command processing, and writing output and error messages. If you do allocate standard files, they must be z/OS UNIX files. If you do not allocate them, stdin, stdout, and stderr default to /dev/null. You allocate the standard files by using the options of the data definition keyword PATH.

Note: The BPXBATCH program also uses the STDENV file to allow you to pass environment variables to the program that is being invoked. This can be useful when not using the shell, such as when using the PGM parameter.

Example:

//STEP1 EXEC PGM=BPXBATCH,PARM='PGM program-name parm1 parm2'
//STDIN DD PATH='/stdin-file-pathname',PATHOPTS=(ORDONLY)
//STDOUT DD PATH='/stdout-file-pathname',PATHOPTS=(OWRONLY,OCREAT,OTRUNC),
// PATHMODE=SIRWXU
//STDERR DD PATH='/stderr-file-pathname',PATHOPTS=(OWRONLY,OCREAT,OTRUNC),
// PATHMODE=SIRWXU
⋮

Parameters:

  • BPXBATCH accepts one parameter string as input. At least one blank character must separate the parts of the parameter string.
  • When BPXBATCH is run from a batch job, the total length of the parameter string must not exceed 100 characters.
  • When BPXBATCH is run from TSO, the parameter string can be up to 500 characters.
  • If neither SH nor PGM is specified as part of the parameter string, BPXBATCH assumes that it must start the shell to run the shell script allocated by stdin.

 

SH | PGM

Specifies whether BPXBATCH is to run a shell script or command or a z/OS XL C/C++ executable file that is located in a z/OS UNIX file.

SH

Instructs BPXBATCH to start the shell, and to run shell commands or scripts that are provided from stdin or the specified program-name.

Note: If you specify SH with no program-name information, BPXBATCH attempts to run anything read in from stdin.

PGM

Instructs BPXBATCH to run the specified program-name as a called program.

If you specify PGM, you must also specify program-name. BPXBATCH creates a process for the program to run in and then calls the program. The HOME and LOGNAME environment variables are set automatically when the program is run, only if they do not exist in the file that is referenced by STDENV. You can use STDENV to set these environment variables, and others.

program-name

Specifies the shell command or the z/OS UNIX path name for the shell script or z/OS XL C/C++ executable file to be run. In addition, program-name can contain option information.

BPXBATCH interprets the program name as case-sensitive.

Defaults:

  • The stdin default is /dev/null.
  • The stdout default is /dev/null.
  • The stdenv default is /dev/null.
  • The stderr default is the value of stdout.
  • If all defaults are accepted, stderr is /dev/null.

Example – Executing USS commands via Job Batch

//LIST     EXEC PGM=BPXBATCH
//STDERR   DD SYSOUT=*
//STDOUT   DD SYSOUT=*
//STDPARM  DD *
sh ls -lap /etc
/*

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.