Example: Running a shell command in batch
In the following example, BPXBATCH runs the shell command compress to
compress the file /usr/lib/junk. To start the next JCL job step before
the compress command completes, the parameter
string is specified as:
SH nohup compress /usr/lib/junk & sleep 1
If, instead, the parameter string is specified as:
SH compress /usr/lib/junk
the
job step waits for the compress shell command
to end. For short-running commands, this is fine. For long-running commands, however, where you want to use BPXBATCH
to start a shell command in the background and not wait for completion,
you must specify the parameter string like this:
SH nohup command args & sleep 1
SH
starts a login shell to parse and run the command.
The login shell parses the &, signifying that the command is to
run asynchronously (in the background), and forks a child process
to run the nohup command. In the child process,
the nohup shell command (which takes another
command as an argument) prevents the process from being terminated
when the login shell returns to BPXBATCH.
In parallel with the nohup processing, the login shell runs the sleep command. Running the sleep command delays the login shell from returning to BPXBATCH until the child process has had enough time (1 second) to protect itself from being terminated. The login shell returns to BPXBATCH, while the child process continues to run the compress command.
Example: User TURBO runs the compress shell
command in batch, as follows:
- STDPARM defines an in-stream data set containing the parameter string.
- STDERR defines a file to which to write error messages, /u/turbo/bin/mystd.err.
- The STDIN and STDOUT files default to /dev/null.
- The STEPLIB is propagated for the execution of the shell and for any processes created by the shell.
//jobname JOB ...
//stepname EXEC PGM=BPXBATCH,REGION=8M
//STEPLIB DD DSN=CEE.SCEERUN,DISP=SHR
//STDERR DD PATH='/u/turbo/bin/mystd.err',
// PATHOPTS=(OWRONLY,OCREAT,OTRUNC),PATHMODE=SIRWXU
//STDPARM DD *
SH nohup compress /usr/lib/junk & sleep 1
/*
Example: The following JCL is similar to the previous example
and produces equivalent results but uses
PARM=
to
specify the parameter string: //jobname JOB ...
//stepname EXEC PGM=BPXBATCH,REGION=8M,
// PARM='SH nohup compress /usr/lib/junk & sleep 1'
//STEPLIB DD DSN=CEE.SCEERUN,DISP=SHR
//STDERR DD PATH='/u/turbo/bin/mystd.err',
// PATHOPTS=(OWRONLY,OCREAT,OTRUNC),PATHMODE=SIRWXU