Relocating Cozbatch Script Commands

Discussion of the COZBATCH utility for z/OS
mwdazzo
Posts: 55
Joined: Fri Jan 07, 2011 10:02 am

Relocating Cozbatch Script Commands

Post by mwdazzo »

I am using cozbatch to run the coz sftp client with password auth. I would like to remove as many script commands out of STDIN DD as possible but leave in a couple that vary by vendor. Like remoteuser, server=, etc.

As a test I tried moving statement coz_bin="/opt/dovetail/coz/bin" into /SYSTEM/etc/ssh/cozsftp_config thinking this would work but it did not. I know I can move these script statements into DD's as in put but can the ones that do not change from vendor to vendor be set permanetly? Thanks

CoZBatch­N½: Copyright (C) 2005-2009 Dovetailed Technologies LLC. A
CoZBatch­N½: version 1.7.5 2010-12-13
CoZBatch­I½: executing progname=login-shell="-/bin/sh"
/cozsftp: FSUM7351 not found
CoZBatch­I½: returning rc=exitcode=127
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

COZBATCH by default just runs a login shell with a Unix shell script read from STDIN. So you can take advantange of any Unix shells script facilities. /etc/ssh/cozsftp_config is not a script file, so moving shell script commands there won't work.

But you can easily move parts of the shell script to a Unix file and "dot in" that file as a script:

Code: Select all

//RUNSFTP EXEC PGM=COZBATCH
//STDIN DD *                                                                            
# Customize these ... 
remoteuser="uid" 
server="remote.host.name" 
servercp="ISO8859-1" 
remotefile="/path/to/file" 
export PASSWD_DSN='//COZUSER.PASSWD(SITE1)' 

.  /local/bin/cozsftp_std_get
/*                                  
//DOWNLOAD DD DSN=&&DOWNLOAD,DISP=(NEW,DELETE), 
//           DCB=(...),SPACE=(...)
// 
And then the file /local/bin/coz_std_config would have:

Code: Select all

coz_bin="/opt/dovetail/coz/bin"                                          
# These can be used to read the ssh password from a (secured) dataset 
# if you don't want to setup public/private keypairs 
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 

$coz_bin/cozsftp  $ssh_opts -b- $remoteuser@$server <<EOB 
lzopts mode=text,servercp=$servercp 
get $remotefile //DD:DOWNLOAD 
EOB 
Also, the source/dot command accepts arguments for the script, so you can get fancy and parameterize your scripts.

And remember - learning Unix and shell scripting on z/OS is a handy skill to have since the language and concepts are portable to real Unix/Linux systems. There are other neat tricks that you can do with COZBATCH, like passing in environment variables from JCL that can be a nice way to integrate the Unix scripting environment with JCL PROC and SET variables. See the COZBATCH User's Guide for more details.
mwdazzo
Posts: 55
Joined: Fri Jan 07, 2011 10:02 am

Post by mwdazzo »

Would there be a way to setup a std proc then be able to over ride the 4 most common variables. remoteuser, server, remotefile, passwd_dsn. I saw the example of pg-8 of the cozbatch user guide and I am wondering if can be done using the jcl set variables?
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

Absolutely - you can pass in environment variables into the COZBATCH script from PARM=, as demonstrated on the COZBATCH User's Guide.

Note that you are still constrained by the JCL 100 character PARM= length, but there is a feature of COZBATCH that can be used to work around that as well:

http://dovetail.com/docs/cozbatch/examples.html (example 6)
mwdazzo
Posts: 55
Joined: Fri Jan 07, 2011 10:02 am

Post by mwdazzo »

I created the proc below, the STDIN DD contains all the script commands. I am trying to over ride the parms with SET jcl statements in my. Job goes down with a rc=126. Any help is appreciated. Thanks

STDERR DD contains:
/cozsftp: FSUM7351 not found
/SERVICE: FSUM9209 cannot execute: reason code = 0b1b011f: EDC5111I Permission denied

CEEDUMP DD contains:
CoZBatch­N½: Copyright (C) 2005-2009 Dovetailed Technologies LLC. All rights res
CoZBatch­N½: version 1.7.5 2010-12-13
CoZBatch­I½: executing progname=login-shell="-/bin/sh"
CoZBatch­I½: returning rc=exitcode=126

//Job XXXX
//SFTPPROC EXEC SFTPPROC
// SET REMOTUSR='pcchsec'
// SET SERVER='sftp.data-mail.com'


//SFTPPROC PROC
// SET REMOTUSR='XXXXXXX'
// SET SERVER='XXX.XXX.XXX.XXX'
//*
//EX2 EXEC PGM=COZBATCH,PARM='REMOTUSR=$remoteuser SERVER=$server'
//STEPLIB DD DISP=SHR,DSN=SYS4.TECH.COZ.LOADLIB
//STDIN DD DISP=SHR,DSN=ST1MAT.CNTL(SFTPSCRP)
//STDERR DD SYSOUT=*
//STDOUT DD SYSOUT=*
//CEEDUMP DD SYSOUT=*
// PEND
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

Try:

/EX2 EXEC PGM=COZBATCH,PARM='remoteuser=&REMOTUSR server=&SERVER'

This willl result in the shell variables $remoteuser and $server being set from the values of the JCL variables REMOTEUSR and SERVER
mwdazzo
Posts: 55
Joined: Fri Jan 07, 2011 10:02 am

Post by mwdazzo »

I modified the proc as you suggested but unfortunately I am getting the same exact error. tks


//SFTPPROC PROC
// SET REMOTUSR='XXXXXXX'
// SET SERVER='XXX.XXX.XXX.XXX'
//EX2 EXEC PGM=COZBATCH,PARM='remoteuser=&REMOTUSR server=&SERVER'
//STEPLIB DD DISP=SHR,DSN=SYS4.TECH.COZ.LOADLIB
//STDIN DD DISP=SHR,DSN=ST1MAT.CNTL(SFTPSCRP)
//STDERR DD SYSOUT=*
//STDOUT DD SYSOUT=*
//CEEDUMP DD SYSOUT=*
// PEND
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

Sorry, I guess I will have to see the script and your job log.
mwdazzo
Posts: 55
Joined: Fri Jan 07, 2011 10:02 am

Post by mwdazzo »

Here is the script and the output dd's. The jcl being used was posted above. Thanks really appreciated Matt


# Customize these ...
remotusr="uid"
server="remote.host.name"
servercp="ISO8859-1"
remotpth="/path/to/file"
export PASSWD_DSN='//ST1MAT.CNTL(PW)'
#
# These can be used to read the ssh password from a (secured) dataset
# if you don't want to setup public/private keypairs
export PASSWD_DSN='//ST1MAT.CNTL(PW)'
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
#
# 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
# get $remotefile //DD:DOWNLOAD
# put //T.TMKINT10.DETAIL.M11032.CUHR.ZIP pchtest.zip
#
$coz_bin/cozsftp $ssh_opts -b- $remotusr@$server <<EOB
lzopts mode=binary,servercp=$servercp
put //T.TMKINT10.DETAIL.M11032.CUHR.ZIP pchtest.zip
EOB
/*


Error msg's below,
//STDERR DD
/cozsftp: FSUM7351 not found
/SERVICE: FSUM9209 cannot execute: reason code = 0b1b011f: EDC5111I Permission

//CEEDUMP DD
CoZBatch­N½: Copyright (C) 2005-2009 Dovetailed Technologies LLC. All rights
CoZBatch­N½: version 1.7.5 2010-12-13
CoZBatch­I½: executing progname=login-shell="-/bin/sh"
CoZBatch­I½: returning rc=exitcode=126

This is the jesjcl DD out

XXEX2 EXEC PGM=COZBATCH,PARM='remoteuser=&REMOTUSR server=&SERVER'
IEFC653I SUBSTITUTION JCL - PGM=COZBATCH,PARM='remoteuser=XXXXXXX ser
XXSTEPLIB DD DISP=SHR,DSN=SYS4.TECH.COZ.LOADLIB
XX* SAVEARGS DD DSN=&&MYTEMP1,DISP=(OLD,PASS)
XXSTDIN DD DISP=SHR,DSN=ST1MAT.CNTL(SFTPSCRP)
XXSTDERR DD SYSOUT=*
XXSTDOUT DD SYSOUT=*
XXSYSOUT DD SYSOUT=*
XXCEEDUMP DD SYSOUT=*
XX PEND
// SET REMOTUSR='pcchsec'
// SET SERVER='sftp.data-mail.com'
mwdazzo
Posts: 55
Joined: Fri Jan 07, 2011 10:02 am

Post by mwdazzo »

I removed a /* that was after the last EOB at the very bottom of the script and now have a different error.

STDERR DD
/cozsftp: FSUM7351 not found

CEEDUMP DD
CoZBatch­N½: Copyright (C) 2005-2009 Dovetailed Technologies LLC.
CoZBatch­N½: version 1.7.5 2010-12-13
CoZBatch­I½: executing progname=login-shell="-/bin/sh"
CoZBatch­I½: returning rc=exitcode=127

Thanks
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

Matt,

Your script no longer contains at setting for $coz_bin. You will need something like:

coz_bin=/path/to/coz/bin

Also, you are still setting this in your script:
remotusr="uid"
server="remote.host.name"

So, you need to remove these since they will be set on the PARM=.
Also, you need to rename the PARM= variable remoteuser to remoteusr to match.

Another helpful thing when writing shell scripts is to add this line at the beginning:

set -x

This will give you a shell script execution trace to stderr.
mwdazzo
Posts: 55
Joined: Fri Jan 07, 2011 10:02 am

Post by mwdazzo »

I found the problem with FSUM7351 not found error. A rookie mistake, I was missing the statement coz_bin="/usr/lpp/coz/bin" in the script.

Now that the script executes it looks like the parameters are not being passed to the script.

Here is the jcl

//ST1SFTP JOB (,TECH),'TECH-M.DAZZO',CLASS=P,
// MSGCLASS=X,NOTIFY=&SYSUID
//PROCS JCLLIB ORDER=(ST1MAT.CNTL)
//SFTPPROC EXEC SFTPROC2
// SET REMOTUSR='pcchsec'
// SET SERVER='sftp.data-mail.com'

Here is the proc

//SFTPPROC PROC
//*
//EX2 EXEC PGM=COZBATCH,PARM='remoteuser=&REMOTUSR server=&SERVER'
//STEPLIB DD DISP=SHR,DSN=SYS4.TECH.COZ.LOADLIB
//* SAVEARGS DD DSN=&&MYTEMP1,DISP=(OLD,PASS)
//STDIN DD DISP=SHR,DSN=ST1MAT.CNTL(SFTPSCRP)
//STDERR DD SYSOUT=*
//STDOUT DD SYSOUT=*
//CEEDUMP DD SYSOUT=*
// PEND
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

See my latest comments above.

Try adding "set -x" to get a trace of your shell script.
mwdazzo
Posts: 55
Joined: Fri Jan 07, 2011 10:02 am

Post by mwdazzo »

OMG finally got it working, thanks so much.

One last question for now at least, how do I over ride the PASSWD_DSN so in the jcl a control card can be used for different vendors.

Thanks
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

PASSWD_DSN is also an environment variable. You can set it on COZBATCH PARM= as well.
Post Reply