Page 1 of 1

The ReturnCode of Unix Shell Script

Posted: Wed Jan 08, 2003 12:44 pm
by kevinds
Hi,

I try to figure out how to get the correct return code from the DSExecute("UNIX",command,output,returncode). Our command is a unix shell script which implements a validation and load logic. Is the returncode the $? which is the return code of last unix code in the shell script or something else? Anyway please help.

Thanks.

Kevin

Posted: Wed Jan 08, 2003 2:51 pm
by chulett
I can't say for sure and this may depend on what shell you are using. For us using Korn, my understanding is that the script returns the code from the last command the script executes. Classic problem is to get an error and 'echo' something about it before exiting the script - what you get is the status of the echo command which more than likely executed with no error. You can override that by using an explicit 'return' statement in the script, which sounds more like what you might want to do.

-craig

Posted: Wed Jan 08, 2003 3:52 pm
by ray.wurlod
Beware, too, that some variants of UNIX only return a single byte of the return code (the least significant byte iirc). This has led in the past to confusion when dsjob has generated return codes in the 3xxxx or 8xxxx range.

Posted: Wed Jan 08, 2003 4:29 pm
by kevinds
Thanks,

I am using the command as

Posted: Wed Jan 08, 2003 4:30 pm
by kevinds
command = "rsh ":db2Host:" -f ":KornScripts

Posted: Wed Jan 08, 2003 8:01 pm
by ray.wurlod
Then you will get the exit status of rsh.

Posted: Thu Jan 09, 2003 7:52 am
by kevinds
Thanks,

then I always see the 0 as the returncode

Posted: Thu Jan 09, 2003 5:05 pm
by ray.wurlod
True provided rsh succeeds (!).

If you don't need any of the other output, you can echo the value of $? and capture this through the third argument of DSExecute(). For example:
command = "rsh ":db2Host:" -f ":KornScripts: "; echo $?"

Probably even better would have the script generate something (a file?) whose existence, if not contents, could be checked.