Checking the UNIX return code from Connect:Direct shell script
How do I check the UNIX return code from Connect:Direct shell script?
Check the $? variable. Use a command like this immediately after the EOF of the "here document":
However be aware that Connect:Direct for UNIX reinterprets return codes to fit a particular scheme. Connect:Direct can issue return codes of 0, 4, 8 and 16 to represent good, warning, error and catastrophic error, respectively. Thus, return codes from run tasks will be re-interpreted to fit that scheme.
Run task completion codes will generate the $? variable as follows:
Completion code <=4, then $? will yield 0
Completion code > 4, then $? will yield 8
For UNIX run task scripts that generate a Completion Code (CC) of 4 or less, you must perform additional tasks to make the $? non-zero.
In the Connect:Direct Process after the run task, add an "if" step that checks the CC of the run task step. If the return code is 4 or less, program it to execute another run task script on the PNODE that only has a statement of exit 5. Then the $? Variable is set to 8 when exiting the Connect:Direct part of the UNIX script.
#running this script will generate a $? Of 8
/cdunix/ndm/bin/direct -x << EOJ
submit maxdelay=00:00:30 proc1 process snode=l1aix1.cd.v3301
step01 run task snode sysopts="/home/acme1/scrpt"
step01a if (step01 lt 5) then
step02 run task snode sysopts="/home/acme1/setcc"
Here is an example of the results of running these example scripts:
$ more scrpt
$ more setcc
The return code for a process is stored in the $? variable within the ksh or sh if the maxdelay=hh:mm:ss parameter is in the process. The maxdelay paramter is designed to force the submit command to wait until the process has completed or the assigned time has expired before returning control back to the shell. Additionally it stores the rc of a process in the $? variable for the ksh and sh. Below is a script that echos the rc for a process back to STDOUT
# This script invokes the Connect:Direct for UNIX CLI
# and submits a process inline to copy a file to a remote
/home/cd3401/cdunix/ndm/bin/direct -x << EOJ
submit maxdelay=00:00:01 proc1 process snode=$SNDE
step1 copy from (file=/home/cd3401/cdunix/mycpio.gz)
Upon completion a Connect:Direct process will return 1 of 4 return codes
16 catastrophic failure