This section contains examples of using the Co:Z Batch utility.
The RUNSHELL member of the Co:Z Toolkit Sample JCL
also contains sample COZBATCH job steps.
Run the user's default shell, which is normally
/bin/sh. The shell is run as a "login" shell so that before reading input fromSTDIN, the shell will have executed/etc/profileand the user's.profileif present. All output: messages, stdout, and stderr will go to a dynamically allocated SYSOUT file.// EXEC PGM=COZBATCH //STDIN DD * env //
Run the user's default shell, but this time direct messages, stdout, and stderr to separate DDs.
// EXEC PGM=COZBATCH //STDIN DD * env //SYSOUT DD SYSOUT=* //STDOUT DD SYSOUT=* //STDERR DD SYSOUT=* //
Run the
/bin/shshell explicity, but not as a login shell. The leading "/" is required to delineate LE runtime options. The output from this execution will display only a few environment variables, since the sytem and user profiles are not executed.// EXEC PGM=COZBATCH,PARM='/ /bin/sh' //STDIN DD * env
Run the
/bin/cat>program explicity, which will copy the input fromSTDINtoSTDOUT// EXEC PGM=COZBATCH,PARM='//bin/cat' //STDIN DD * xxxx yyyyy zzz //STDOUT DD SYSOUT=* //
Use DD
STDENVto have LE present environment variables. Additional environment variables are set usingPARM=, which allows for the substitution of JCL "SET" or "PROC" variables. Since a program name is not specified, the user's default login shell is executed and will read input fromSTDIN.// SET MACLIB=SYS1.MACLIB // SET AMACLIB=SYS1.AMACLIB //* // EXEC PGM=COZBATCH, // PARM='/ TDIR=/usr/local/bin MACLIB=&MACLIB AMACLIB=&AMACLIB' //STDENV DD * ADIR=foo //STDIN DD * echo ls ADIR=$ADIR ls $ADIR echo ls TDIR=$TDIR ls $TDIR echo MACLIB=$MACLIB AMACLIB=$AMACLIB env //
In a situation where you have several JCL SET or PROC variables that need to be used as environment variables, you can be limited by the evil 100-character JCL PARM= limit. COZBATCH allows you to have multiple steps that concatenate these variables to a temp dataset that is eventually passed into a COZBATCH step that uses them in a shell script. The DD name for the file used to save these aruments is
SAVEARGS.Note that steps that have neither a
STDINDD nor name an explicit program to execute will actually not run anything, but simply set and save arguments.// SET PRFX=SYS1.INSTALL.FOOBAR.LONGNAME.DEMO // SET MACLIB=&PRFX..MACLIB // SET AMACLIB=&PRFX..AMACLIB // SET AMODGEN=&PRFX..AMODGEN // SET LINKLIB=&PFX..LINKLIB //* //EX1 EXEC PGM=COZBATCH,PARM='/MACLIB=&MACLIB AMACLIB=&AMACLIB' //SAVEARGS DD DSN=&&MYTEMP1,DISP=(NEW,PASS) //* //EX2 EXEC PGM=COZBATCH,PARM='/AMACLIB=&AMODGEN' //SAVEARGS DD DSN=&&MYTEMP1,DISP=(OLD,PASS) //* //EX3 EXEC PGM=COZBATCH,PARM='/LINKLIB=&LINKLIB' //SAVEARGS DD DSN=&&MYTEMP1,DISP=(OLD,PASS) //STDIN DD * echo MACLIB=$MACLIB echo AMACLIB=$AMACLIB echo AMODGEN=$AMODGEN echo LINKLIB=$LINKLIB //*
The special
PARM=variable$?maybe be used to specify a return code for the step, overriding the use of the program or shell's exit code. In the special case where a program orSTDINDD is not present, a program or shell is not executed - but this feature will still set the return code.// SET MYRC=8 //SETRC1 EXEC PGM=COZBATCH,PARM='/ $?=&MYRC' //* //SETRC2 EXEC PGM=COZBATCH,PARM='/ FOO=BAR $?=&MYRC' //STDIN DD * env //
Unlike BPXBATCH or BPXBATSL, arguments specified to the program on the
PARM=keyword may be quoted.// EXEC PGM=COZBATCH, // PARM='/"TDIR=&TDIR" "FIL=&FIL" /bin/sh -c "cd $TDIR; pax -rvf $FIL"'
Since COZBATCH executes a shell in the original address space, it is easy to write shell scripts inline in your JCL that use DD statements. The synergy of features allows you to fully and easily exploit z/OS Unix in batch job steps.
// SET TCHOME="/usr/local/tomcat" // SET INSTJCL=TOMCAT.INSTALL.JCL //* //INSTALL EXEC PGM=COZBATCH,PARM='/TCHOME=&TCHOME' //PAX DD DSN=&INSTJCL(PAXBIN),DISP=SHR //STDIN DD * cd $TCHOME if [[ $(ls | wc -l) -gt 0 ]]; then echo directory $TCHOME is not empty! exit 8 fi pax -rvf //DD:PAX //
COZBATCH can be used with the Co:Z toolkit
fromdsnandtodsnshell commands.//REGEX EXEC PGM=COZBATCH //IN DD DSN=SYS1.MACLIB(ACB),DISP=SHR //OUT DD DSN=&&TEMP,DISP=(NEW,PASS), // SPACE=(CYL,(1,1)), // DCB=(LRECL=80,RECFM=FB) //STDIN DD * # Copy lines matching a regular expression to DD:OUT fromdsn //DD:IN | grep BLKSIZE | todsn //DD:OUT //
COZBATCH can be used with Co:Z SFTP to script a batch SFTP client job to download a file to an MVS dataset.
// SET RLOGIN='userid@remote.host' // SET RFILE='/path/to/remote/file' //* //RUNCOZ EXEC PGM=COZBATCH, // PARM='/RLOGIN=&RLOGIN RFILE=&RFILE' //STDIN DD * # These can be used to read the ssh password from a (secured) dataset # if you don't want to setup public/private keypairs coz_bin="/opt/dovetail/coz/bin" export PASSWD_DSN='//SECURE.PASSWD(SITE1)' export SSH_ASKPASS=$coz_bin/read_passwd_dsn.sh export DISPLAY=none ssh_opts="-oBatchMode=no" # allows ssh to use SSH_ASKPASS program ssh_opts="$ssh_opts -oConnectTimeout=60" ssh_opts="$ssh_opts -oServerAliveInterval=60" ssh_opts="$ssh_opts -oStrictHostKeyChecking=no" # accept initial host keys # Invoke the Co:Z sftp client with an in-line batch of commands # that downloads a remote file to a local DD. # Note that "-oBatchMode=no" must be specified before "-b" # since ssh opts are first-sticky $coz_bin/cozsftp $ssh_opts -b- $RLOGIN <<EOB lzopts mode=text get $RFILE //DD:DOWNLOAD EOB //DOWNLOAD DD DSN=&&DOWNLOAD,DISP=(NEW,PASS), // DCB=(...),SPACE=(...) //