Return codes

Discussion of Co:Z sftp, a port of OpenSSH sftp for z/OS
Post Reply
gngrossi
Posts: 38
Joined: Sat Mar 06, 2010 6:10 pm

Return codes

Post by gngrossi »

I am looking for documentation that provides the return codes when running cozsftp in batch. Specifically RCs that are higher than 0 and less than 9.

We are migrating away from another product and a Unix file not found resulted in a RC higher than 4. Co:Z SFTP uses RC=1 which is lower than expected.

Thanks.
dovetail
Site Admin
Posts: 2025
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

The Co:Z SFTP client uses the same exit codes as the OpenSSH client. They generally aren't too useful, but here they are:

"0" means that no errors occurred, or an error occurred in batch mode and the subcommand that had an error was prefixed with "-"

"1" means that a command or function had an error

"255" is used for fatal errors.

If you want to exit your shell script (say, in COZBATCH) with a different return code, then you can add something like this to your script:

Code: Select all

# add this at end if your script after the cozsftp command
# and its input sub-commands
rc=$?
if [[ $rc -ne 0 ]]; then
  exit 8
fi
gngrossi
Posts: 38
Joined: Sat Mar 06, 2010 6:10 pm

Post by gngrossi »

That is very helpful.

If a job uses multiple sub-commands then the RC is always captured appropriately, right?
For example:
If the first get receives a non-zero RC, the second get is not executed so the RC is always set for the last command executed.

get $remotefile1 //DD:FILE1
get $remotefile2 //DD:FILE2
EOB
RC=$?
if [ $RC -ne 0 ] ; then { exit 8; } fi
//
dovetail
Site Admin
Posts: 2025
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

Yes, if you have batch mode enabled (-b), then the first command that fails that is one of these:

get, put, rename, ln, rm, rmdir, mkdir, cd, ls, lcd, chmod, chown, chgrp, lpwd and lmkdir

will cause the batch to exit with a non-zero return code, unless you prefix the command with a dash ('-').
Post Reply