About | First REXX Program | Favorites | Mainframes (z/OS) | Skydiving |

Windows .BAT Scripts for Uploading files to z/OS Mainframe

.BAT Coding for z/OS Uploading

As mentioned on Millennial Mainframer.

Here’s some glorious nerdry I’ve been laboring at work to make my and others’ lives easier creating Windows .BAT scripts for uploading files to z/OS mainframe.  Before this all this all the declarations for z/OS allocations were manually done and very time consuming.

The code is pretty straight forward once you start playing with it.

Some irritations you’ll find with Windows batch files (we’re still using XP regretfully) is that while it’s not CASE sensitive…there’s some strict syntax and limitations.

For example I was struggling with IF ELSE statements which require a strict format; spacing when outputting to a textfile; and using global and local variables within the script which ended up with me creating multiple procedures as a workaround.

Since Batch files in Windows are pretty limited I would have LOVED to use PowerShell.
However I knew that a simple .BAT would at least guarantee to work on our secure workstations.

(Note: The following code below works as presented with spacing and format.)


 

VANGUARD Maintenance Upload Batch Script

@echo off
::: -- Set the window color --
COLOR 1F
::: -- Set the window title --
SET "title=VANGUARD MAINTENANCE UPLOAD BATCH SCRIPT - version 0.5"
TITLE %title%
::: -- Set the window size --
MODE CON: COLS=100 LINES=50
::: -- Script Header --
echo ****************************************
echo.
echo VANGUARD MAINTENANCE UPLOAD BATCH SCRIPT
echo.
echo ****************************************
echo * * 
echo * READ THE FOLLOWING BELOW * 
echo * * 
echo * This script will: *
echo * *
echo * 1). Calculate needed CYLINDER * 
echo * * 
echo * 2). FTP MAINT file to proper *
echo * location * 
echo * * 
echo * ------------------------------------ * 
echo * Please ensure the following: *
echo * *
echo * 1). MAINT file is in same *
echo * same directory as this .BAT *
echo * * 
echo * 2). Filename format is: *
echo * * 
echo * Qnyy.MAINT * 
echo * * 
echo * e.g. Q413.MAINT * 
echo * ------------------------------------ * 
echo * * 
echo ****************************************
echo.
::: -- SIMPLE ERROR CHECKING --
set /p UserFileName= What's the MAINT file name? (e.g. Q114.MAINT): 
IF EXIST "%UserFileName%" ( 
 set filename=%UserFileName%
) else ( 
 echo Invalid filename
 pause 
 goto :eof
)
::: -- Change BYTES TO KILOBYTES --
echo.
for %%A in (%filename%) do set /a x=%%~zA/1024
for %%A in (%filename%) do echo.Size of "%%A" is %x% kilobytes
::: -- IF filesize < 675 PRI Cylinder will be 1 -- 
IF %x% LEQ 675 ( 
 call :setprimary_tiny 1
) else ( 
 call :setprimary_big %x% 

)
::: -- Configure PRIMARY CYLINDER --
:setprimary_tiny
set iPRI=%1
echo PRIMARY CYLINDERS = %iPRI%
echo FILENAME = %filename%
call :ftp_upload
:setprimary_big
set /a y=%1 / 675 + 1
set iPRI=%y%
echo PRIMARY CYLINDERS = %iPRI%
echo FILENAME = %filename%
call :ftp_upload
::: -- FTP Upload MAINT file --
:ftp_upload
IF EXIST ftptemp.txt del ftptemp.txt
echo.
set /p FTPhost=FTP Host?:
set host=%FTPhost%
set /p FTPUserID=FTP User?:
REM ----------------------------------------------
REM Herbert Kleebauer ascii-binary password mask
REM ----------------------------------------------
echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5>%temp%\ftp.com
set /p FTPPwd=FTP Password?: <nul
for /f "tokens=*" %%i in ('%temp%\ftp.com') do set "FTPPwd=%%i"
del %temp%\ftp.com
REM ----------------------------------------------
echo user %FTPUserID%>> ftptemp.txt
echo %FTPPwd%>> ftptemp.txt
echo bin>> ftptemp.txt
echo prompt>> ftptemp.txt
echo cd ..>> ftptemp.txt
echo cd IPP.VIP.AVSS113>> ftptemp.txt
echo quote site volume=ppins1 recfm=fb lrecl=80 cyl>> ftptemp.txt
echo quote site pri=%iPRI%>> ftptemp.txt
echo put %filename% %filename% )R>> ftptemp.txt
echo quit >> ftptemp.txt
ftp -n -s:ftptemp.txt %host%
del ftptemp.txt
pause
exit

 

 

SYNCSORT Maintenance Upload Batch Script

@echo off
::: -- LOGIC--
::: 
::: FTP UPLOAD TO HOST USING INPUT FROM USER AND CREATING TEMP TEXT FILE
:::
::: -- Set the window color --
COLOR 1F
::: -- Set the window title --
SET "title=SYNCSORT MAINTENANCE UPLOAD BATCH SCRIPT - version 0.5"
TITLE %title%
::: -- Set the window size --
MODE CON: COLS=100 LINES=50
::: -- Script Header --
echo ****************************************
echo.
echo SYNCSORT MAINTENANCE UPLOAD BATCH SCRIPT
echo.
echo ****************************************
echo * * 
echo * READ THE FOLLOWING BELOW * 
echo * * 
echo * This script will: *
echo * *
echo * 1). Set host parms for files * 
echo * * 
echo * 2). FTP MAINT files to proper *
echo * location * 
echo * * 
echo * ------------------------------------ * 
echo * Please ensure the following: *
echo * *
echo * 1). Installation files dowloaded *
echo * from ftp://www.syncsort.com *
echo * are in the same directory *
echo * as this .BAT *
echo * * 
echo * ------------------------------------ * 
echo * * 
echo ****************************************
echo.
call :ftp_upload
::: -- FTP Upload MAINT file --
:ftp_upload
IF EXIST ftptemp.txt del ftptemp.txt
echo.
set /p FTPhost=FTP Host?:
set host=%FTPhost%
set /p FTPUserID=FTP User?:
REM ----------------------------------------------
REM Herbert Kleebauer ascii-binary password mask
REM ----------------------------------------------
echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5>%temp%\ftp.com
set /p FTPPwd=FTP Password?: <nul
for /f "tokens=*" %%i in ('%temp%\ftp.com') do set "FTPPwd=%%i"
del %temp%\ftp.com
REM ----------------------------------------------
echo user %FTPUserID%>> ftptemp.txt
echo %FTPPwd%>> ftptemp.txt
echo bin>> ftptemp.txt
echo prompt>> ftptemp.txt
echo cd ..>> ftptemp.txt
echo cd IPP.SYNCSORT>> ftptemp.txt
echo quote site volume=ppins1 lrecl=1024 recfm=fb blksize=6144>> ftptemp.txt
echo quote site track pri=350 sec=100>> ftptemp.txt
echo mput *.F1 )R>> ftptemp.txt
echo mput *.F2 )R>> ftptemp.txt
echo mput *.SMPMCS )R>> ftptemp.txt
echo mput *.JCL )R>> ftptemp.txt
echo mput *.PAXLIB )R>> ftptemp.txt
echo mput *.ISP* )R>> ftptemp.txt
echo mput *.MODLIB )R>> ftptemp.txt
echo mput *.SAMPJCL )R>> ftptemp.txt
echo ascii>> ftptemp.txt
echo quote site volume=ppins1 lrecl=80 recfm=fb blksize=3120>> ftptemp.txt
echo quote site track pri=2 sec=22>> ftptemp.txt
echo mput *.TXT )R>> ftptemp.txt
echo quit>> ftptemp.txt
ftp -n -s:ftptemp.txt %host%
del ftptemp.txt
pause
exit

EDIT:

Found some amazing ASCII-binary code on the various Google Groups  on old UserNet post from a clever Assembler Programmer named Herbert Kleebauer.

This code snippet hides user input for the FTP password part.

I’ve test this on XP and Win7 and both appear to work.

@echo off
echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5>%temp%\ftp.com
set /p password=What is your password? <nul
for /f "tokens=*" %%i in ('%temp%\ftp.com') do set "password=%%i"
del %temp%\ftp.com
echo password is "%password%"
pause

EDIT2:

Email reply from the Man himself:
Herbert Kleebauer
12:53 PM (10 minutes ago) to me

On 28.02.2014 16:02, Paul Gamble wrote:

> You’ve impressed me with what’s possible with BATCH using ascii-binary, and want to thank you for that!

BATCH using ascii-binary was very helpful in the good
old days. But 64 bit Windows doesn’t allow the execution of
16 bit com programs. A way to include 32 bit code is, to use
certutil.exe, but this is not available before Vista.

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
:: read char from keyboard (stdin) until is pressed
:: write characters to stdout
:: write * to stderr
certutil -f -decode %~f0 inpass.exe>nul
set /p =Enter password: echo.
echo %password%
del inpass.exe
goto :eof
-----BEGIN CERTIFICATE-----
TVpgAQEAAAAEAAAA//8AAGABAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAoAAAAA4fug4AtAnNIbgBTM0hTmljZSB0byBtZWV0IHNvbWVi
b2R5IHdobyBpcyBzdGlsbCB1c2luZyBET1MsDQpidXQgaGlzIHByb2dyYW0gcmVx
dWlyZXMgV2luMzIuDQokAFBFAABMAQEAUHmlNgAAAAAAAAAA4AAPAQsBBQwAAgAA
AAAAAAAAAADIEAAAABAAAAAgAAAAAEAAAB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AAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAA==
-----END CERTIFICATE-----

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

The source code:

winmain::

_20:    bsr.l   getc
        cmp.b   #13,r0
        beq.b   _10
        bsr.l   putc
        move.b  #'*',r0
        bsr.l   putc2
        br.b    _20
_10:    jsr.l   (ExitProcess)


putc2:  move.l  r0,-(sp)
        move.b  r0,buf
        eor.l   r0,r0
        add.l   handle2,r0
        bne.b   .p_10
        moveq.l #-12,-(sp)
        jsr.l   (GetStdHandle)
        move.l  r0,handle2
        br.b    .p_10

putc:   move.l  r0,-(sp)
        move.b  r0,buf
        eor.l   r0,r0
        add.l   handle1,r0
        bne.b   .p_10
        moveq.l #-11,-(sp)
        jsr.l   (GetStdHandle)
        move.l  r0,handle1
.p_10:  moveq.l #0,-(sp)
        move.l  #count,-(sp)
        moveq.l #1,-(sp)
        move.l  #buf,-(sp)
        move.l  r0,-(sp)
        jsr.l   (WriteFile)
        or.l    r0,r0
        bne.b   _20
_30:    moveq.l #0,-(sp)
        jsr.l   (ExitProcess)
_20:    cmp.l   #1,count
        bne.b   _30
        move.l  (sp)+,r0
        rts.l

getc:   eor.l   r0,r0
        add.l   handle0,r0
        bne.b   _10
        moveq.l #-10,-(sp)
        jsr.l   (GetStdHandle)
        move.l  r0,handle0
        move.l  #mode,-(sp)
        move.l  r0,-(sp)
        jsr.l   (GetConsoleMode)
        and.b   #%11100001,mode
        move.l  mode,-(sp)
        move.l  handle0,-(sp)
        jsr.l   (SetConsoleMode)
        move.l  handle0,r0

_10:    moveq.l #0,-(sp)
        move.l  #count,-(sp)
        moveq.l #1,-(sp)
        move.l  #buf,-(sp)
        move.l  r0,-(sp)
        jsr.l   (ReadFile)
        or.l    r0,r0
        bne.b   _20
        moveq.l #0,-(sp)
        jsr.l   (ExitProcess)
_20:    movu.bl buf,r0
        cmp.l   #1,count
        beq.b   _30
        move.l  #-1,r0
_30:    rts.l


        even4
        blk.l   256     ; because of trace cache
buf:    blk.l   1
mode:   blk.l   1
handle0:blk.l   1
handle1:blk.l   1
handle2:blk.l   1
count:  blk.l   1

One Response to “Windows .BAT Scripts for Uploading files to z/OS Mainframe”

Leave a Reply