The ReturnCode of Unix Shell Script

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
kevinds
Participant
Posts: 4
Joined: Wed Jan 08, 2003 8:25 am

The ReturnCode of Unix Shell Script

Post 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
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
kevinds
Participant
Posts: 4
Joined: Wed Jan 08, 2003 8:25 am

Post by kevinds »

Thanks,

I am using the command as
kevinds
Participant
Posts: 4
Joined: Wed Jan 08, 2003 8:25 am

Post by kevinds »

command = "rsh ":db2Host:" -f ":KornScripts
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Then you will get the exit status of rsh.
kevinds
Participant
Posts: 4
Joined: Wed Jan 08, 2003 8:25 am

Post by kevinds »

Thanks,

then I always see the 0 as the returncode
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
Post Reply