Relocating Cozbatch Script Commands
Relocating Cozbatch Script Commands
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
CoZBatchN½: Copyright (C) 2005-2009 Dovetailed Technologies LLC. A
CoZBatchN½: version 1.7.5 2010-12-13
CoZBatchI½: executing progname=login-shell="-/bin/sh"
/cozsftp: FSUM7351 not found
CoZBatchI½: returning rc=exitcode=127
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
CoZBatchN½: Copyright (C) 2005-2009 Dovetailed Technologies LLC. A
CoZBatchN½: version 1.7.5 2010-12-13
CoZBatchI½: executing progname=login-shell="-/bin/sh"
/cozsftp: FSUM7351 not found
CoZBatchI½: returning rc=exitcode=127
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:
And then the file /local/bin/coz_std_config would have:
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.
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=(...)
//
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
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.
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)
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)
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:
CoZBatchN½: Copyright (C) 2005-2009 Dovetailed Technologies LLC. All rights res
CoZBatchN½: version 1.7.5 2010-12-13
CoZBatchI½: executing progname=login-shell="-/bin/sh"
CoZBatchI½: 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
STDERR DD contains:
/cozsftp: FSUM7351 not found
/SERVICE: FSUM9209 cannot execute: reason code = 0b1b011f: EDC5111I Permission denied
CEEDUMP DD contains:
CoZBatchN½: Copyright (C) 2005-2009 Dovetailed Technologies LLC. All rights res
CoZBatchN½: version 1.7.5 2010-12-13
CoZBatchI½: executing progname=login-shell="-/bin/sh"
CoZBatchI½: 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
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
//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
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
CoZBatchN½: Copyright (C) 2005-2009 Dovetailed Technologies LLC. All rights
CoZBatchN½: version 1.7.5 2010-12-13
CoZBatchI½: executing progname=login-shell="-/bin/sh"
CoZBatchI½: 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'
# 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
CoZBatchN½: Copyright (C) 2005-2009 Dovetailed Technologies LLC. All rights
CoZBatchN½: version 1.7.5 2010-12-13
CoZBatchI½: executing progname=login-shell="-/bin/sh"
CoZBatchI½: 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'
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
CoZBatchN½: Copyright (C) 2005-2009 Dovetailed Technologies LLC.
CoZBatchN½: version 1.7.5 2010-12-13
CoZBatchI½: executing progname=login-shell="-/bin/sh"
CoZBatchI½: returning rc=exitcode=127
Thanks
STDERR DD
/cozsftp: FSUM7351 not found
CEEDUMP DD
CoZBatchN½: Copyright (C) 2005-2009 Dovetailed Technologies LLC.
CoZBatchN½: version 1.7.5 2010-12-13
CoZBatchI½: executing progname=login-shell="-/bin/sh"
CoZBatchI½: returning rc=exitcode=127
Thanks
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.
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.
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
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