Tuesday, September 13, 2011

Nostalgia … NOT


Day 16



Today I was asked if I would dig out an example of automating a Connect:Direct transfer using a Windows batch script.  



I actually prefer to use WSH (Windows Script Host/VBScript) scripts for doing anything more complicated than a one line command when scripting with Connect:Direct on Windows.



I did find one however and have added a few comments to explain what it is doing.



send.bat



@echo off

:: Usage: send c:\directory\from.txt x:\target\to.txt CD.REMOTE.NODE
::
:: NB. This script does not handle spaces in file names well.
::     Place this script in the same directory as the direct.exe program.
::     in the "Common Utilities" sub-directory where Connect:Direct is installed.

:: Count how many arguments we have on the command line
set argC=0
for %%x in (%*) do Set /A argC+=1

if %argC% NEQ 3 (
        echo.
        echo Usage: send c:\directory\from.txt x:\target\to.txt CD.REMOTE.NODE
        goto end:
)

:: Get a random number to name temporary files so we do not clash with any other instances of this script
set num=%random%

:: Build up the Connect:Direct process statements
echo SUBMIT MAXDELAY=01:00:00         >  send_%num%.inp
echo SEND PROCESS                     >> send_%num%.inp
echo         SNODE="%3"               >> send_%num%.inp
echo         CLASS=1                  >> send_%num%.inp
echo         PRTY=1                   >> send_%num%.inp
echo SENDIT COPY                      >> send_%num%.inp
echo         FROM (                   >> send_%num%.inp
echo                 FILE="%1"        >> send_%num%.inp
echo         ) TO (                   >> send_%num%.inp
echo                 FILE="%2"        >> send_%num%.inp
echo                 DISP=RPL         >> send_%num%.inp
echo         )                        >> send_%num%.inp
echo         COMPRESS Extended        >> send_%num%.inp
echo PEND;                            >> send_%num%.inp
echo quit;                            >> send_%num%.inp

:: Submit the Connect:Direct process
direct < send_%num%.inp > send_%num%.out
:: Find the line in the output that contains the process number
find "SEND" send_%num%.out | find /V "-----" > send_%num%.lin
:: Build up the command to get the result of the process
echo select statistics                                     >  cdstat_%num%.inp
FOR /F "tokens=2" %%i in (send_%num%.lin) do @echo pnumber=%%i; >> cdstat_%num%.inp
echo quit; >> cdstat_%num%.inp
:: Submit the command to get the result of the process/transfer
direct -x < cdstat_%num%.inp

:: Clean up temporary files
del /Q send_%num%.inp send_%num%.out send_%num%.lin cdstat_%num%.inp
:end








So below is an example session using the script.
…\Common Utilities>send c:\source.txt dest.txt CD.REMOTE.NODE
Connect:Direct Command Line Interface
Version 4.4.00 Build 051
Copyright(c) 1983, 2007 Sterling Commerce, Inc.
*************************************************
Successfully connected to CD.LOCAL.NODE
> select statistics                                     
pnumber=36
==============================================================================
                                Select Statistics
==============================================================================
P RECID LOG TIME             PNAME     PNUMBER STEPNAME  CCOD  FDBK  MSGID
E RECID LOG TIME             MESSAGE TEXT
------------------------------------------------------------------------------
P SUBP   09/13/2011 09:36:47 SEND      36               0    0      LCCA013I
E QCEX   09/13/2011 09:36:47                                                                                                   
P PSTR   09/13/2011 09:36:47 SEND      36               0    0      LSMG200I
P PSTR   09/13/2011 09:36:47 SEND      36               0    0      LSMG200I
E LSST   09/13/2011 09:36:47                                                                                                   
E RSST   09/13/2011 09:36:47                                                                                                   
P CTRC   09/13/2011 09:36:47 SEND      36      SENDIT   0    0      SCPA000I
P PRED   09/13/2011 09:36:47 SEND      36               0    0      LSMG252I
P PRED   09/13/2011 09:36:47 SEND      36               0    0      LSMG252I
> quit
Successfully disconnected from CD.LOCAL.NODE




Above you will be looking for ideally zeros in the “CCOD” column and for transfers you will be looking to see the row with “RECID” of “CTRC” (Copy Termination Record) indicating that a transfer was successful.

In whatever is calling this send.bat script you can check the %ERRORLEVEL% to see if the transfer was successful.  A value of 0 means success, a value of 4 is warning and a value of 8 or more is an error.

If you did not have the MAXDELAY clause on the submit command the return code in most cases would be zero as submitting a process to the TCQ almost always succeeds unless the there is a communication problem with the local node such as the node is not running.

No comments: