How to get multiple zip files (*.zip) , creating unique DSNs

Discussion of the COZBATCH utility for z/OS
Post Reply
cvs
Posts: 7
Joined: Mon Jan 16, 2012 3:17 pm

How to get multiple zip files (*.zip) , creating unique DSNs

Post by cvs »

I currently use the following script to retrieve one to many files:
r_file="*.txt"
:
:
:
{
cozsftp $ssh_opts -b- $r_user@$r_server <<EOB
ls -l $r_dir/$r_file
EOB
} | awk '
BEGIN {
print "lzopts " ENVIRONÝ"zopts"¨
print "ls -l " ENVIRONÝ"x_dir"¨
}
{
if ($1 == "cozsftp>") next;
print "get " $9 " //DD:UPLOAD"
print "rm " $9
}
END {
print "ls -l " ENVIRONÝ"x_dir"¨
}' |
cozsftp $ssh_opts -b- $r_user@$r_server

I have a need to change "r_file="*.txt" to ” r_file="*.zip" or ” r_file="*.pgp"
The above script works fine to concatenate files to //DD:UPLOAD
I need to create separate files for unzipping or decrypting purposes.
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Re: How to get multiple zip files (*.zip) , creating unique

Post by dovetail »

I assume that the existing script does concatenation because the DD has DISP=MOD.

If you want to get multiple files and have each go to a separate dataset or file, you will need to supply a new file or dataset name for each "get" statement. I don't see a way to use DD statements with such a requirement.

If the remote file names follow MVS dataset naming conventions, you could retreive them, keeping the same name, under a dataset qualifier/level. Otherwise, you would have to retrieve them to a zFS/HFS directory.

If you are just going to retrieve files and keep the same name, you only need a simple script:

Code: Select all

r_file="*.txt"
l_dir="/my/local/dir"    # or l_dir="//HLQ.XXX"
...
cozsftp $ssh_opts -b- $r_user@$r_server <<EOB 
lcd $l_dir
lzopts $zopts 
get $r_file
EOB
Another option might be to use your existing script, but somehow change the line:

Code: Select all

print "get " $9 " //DD:UPLOAD" 
to replace "'//DD:UPLOAD" with a unique generated dataset name for each file.
cvs
Posts: 7
Joined: Mon Jan 16, 2012 3:17 pm

Re: How to get multiple zip files (*.zip) , creating unique

Post by cvs »

The following code will generate TS.SFTP.ZIPnnnn (where nnnn is a value from 0001 - 9999).
The awk loop utilizing "printf("get %s //TS.SFTP.ZIP%04d\n", $9, ++cnt)" handles this very nicely.
Also, there's an ICEMAN step to PARSE the files names out of STDOUT from COZSFTP step.
:
:
:
cozsftp $ssh_opts -b- $r_user@$r_server <<EOB
# +----------------------------+
# ¦ create list for awk loop ¦
# +----------------------------+
ls -l $r_dir/$r_file
EOB
} | awk '
BEGIN {
cnt = 0
}
{
# +-----------------------------------------------------------+
# ¦ awk loop to create get command with incemented file name ¦
# +-----------------------------------------------------------+
if ($1 == "cozsftp>") next;
printf("get %s //TS.SFTP.ZIP%04d\n", $9, ++cnt)
}
END {
}' |
# +------------------------+
# ¦ execute get commands ¦
# +------------------------+
cozsftp $ssh_opts -b- $r_user@$r_server
/*
//*
//*------------------------- STEP FUNCTION ---------------------------*
//* ICEMAN - PARSE OUT FILE NAMES *
//*-------------------------------------------------------------------*
//ICEMAN EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=TS.SFTP.STDOUT,DISP=SHR <IC>
//SORTOUT DD DSN=TS.SFTP.SORTOUT, <IC>
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=0),
// SPACE=(27920,(3,1),RLSE), RECS=1000
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSTF
//SYSIN DD *
OPTION COPY
INCLUDE COND=(1,8,SS,EQ,C'Fetching')
INREC PARSE=(%=(ENDAT=C'to //'),
%00=(FIXLEN=80)),
BUILD=(%00)
/*
Post Reply