dsjob has status=0 even though job aborts

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

davebert99
Participant
Posts: 9
Joined: Fri May 29, 2009 9:23 am

dsjob has status=0 even though job aborts

Post by davebert99 »

I have a sequence job that includes an exception handler that emails if any job aborts. This works fine. However when I run the run from the command line using dsjob the exit code is always 0 whether an error occurred or not. I get the email when an error occurs, but how can I set the exit code so that I can trap it from my Unix script?

I created an error in a parallel job and ran the sequence job below. I received an error email.

dsjob -run -wait myproj myjob
Waiting for job...
Finished waiting for job
Status code = 0
> echo $?
0
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

That just means the Sequence job itself ran to completion without issue. Look into the use of the Terminator stage after the email notification if you want the Sequence to abort as well.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The status of dsjob was correctly 0. It (the dsjob command itself) completed successfully.

If you want the status of dsjob to be the status of the job itself, then you must use the -jobstatus option rather than the -wait option.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

And then they'll always get a one rather than a zero. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Not true. If the job aborts they get 3. If it finishes with warnings they get 2. If they used -mode RESET they get 21. And so on.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chitravallivenkat
Participant
Posts: 106
Joined: Thu Jun 08, 2006 8:51 am

Post by chitravallivenkat »

dsjob -run -wait myproj myjob
Waiting for job...
Finished waiting for job
Status code = 0
> echo $?
0

This says waiting finished successfully. that is why status code shows 0.
Is it necessary to give wait here.

Venkat
nagarjuna
Premium Member
Premium Member
Posts: 533
Joined: Fri Jun 27, 2008 9:11 pm
Location: Chicago

Post by nagarjuna »

When you use that option then it wont return the prompt till job completes .you can use -jobstatus also to acheive the same
Nag
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

ray.wurlod wrote:Not true. If the job aborts they get 3. If it finishes with warnings they get 2. If they used -mode RESET they get 21. And so on.
My statements have been based on my assumption that their Sequence job is always running to completion 'without error' and the errors mentioned are when jobs under the control of the Sequence fail. I don't believe the Sequence itself is failing, in other words.

We shall see. [shrug]
-craig

"You can never have too many knives" -- Logan Nine Fingers
davebert99
Participant
Posts: 9
Joined: Fri May 29, 2009 9:23 am

Post by davebert99 »

Regretfully I do not have premium access so I cannot see your answer.... I added a terminator_activity after the email, but the seq job still returns exit code 0.

I tried setting -jobstatus on the dsjob command line, but that returned 1 (job finished OK) instead of 0 for jobs that completed.
ray.wurlod wrote:The status of dsjob was correctly 0. It (the dsjob command itself) completed successfully.

If you want the status of dsjob to be the status of the job itself, then you must us ...
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Clarify what is aborting here - the Sequence job itself, job(s) it is running or both? If the Sequence job aborts and you are using -jobstatus you will get a 3 rather than a 1.
-craig

"You can never have too many knives" -- Logan Nine Fingers
davebert99
Participant
Posts: 9
Joined: Fri May 29, 2009 9:23 am

Post by davebert99 »

One of the parallel jobs called by the seq job is aborting. I added a separate "exception handler"-->"notification activity"-->"terminator_activity" to the seq job to try and trap the abort, email me and (hopefully) return an exit code other than zero. So basically the seq job looks like:
"job1"-->"job2"-->"job3"-->"job_last"
"excp"-->"email"-->"term"
Job3 is aborting which triggers the excp.
chulett wrote:Clarify what is aborting here - the Sequence job itself, job(s) it is running or both? If the Sequence job aborts and you are using -jobstatus you will get a 3 rather than a 1. ...
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Didn't quite answer the question. Does the Sequence job itself abort? That's the crux of the issue and something the Terminator should be doing for you.
-craig

"You can never have too many knives" -- Logan Nine Fingers
davebert99
Participant
Posts: 9
Joined: Fri May 29, 2009 9:23 am

Post by davebert99 »

In the log in the Director I see:

Starting my_seq_job
Waiting for Job1 to start; Waiting for Job1 to finish
Job1 as finished, status=1 (Finished OK)
Waiting for Job2 to start; Waiting for Job2 to finish
Job2 as finished, status=1 (Finished OK)
Waiting for Job3 to start; Waiting for Job3 to finish
Job3 has finished, status=3 (aborted)
Executing Exception_Handler
Sent message to {my_email}
(fatal error from Terminator_activity) Sequence abort requested
Job my_seq_job aborted
chulett wrote:Didn't quite answer the question. Does the Sequence job itself abort? That's the crux of the issue and something the Terminator should be doing for you. ...
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

OK, good - now the Sequence is aborting as well and will return an exit status of "3" when using the -jobstatus option. If that's not what is happening, make sure you are using it by itself and not in conjunction with the -wait option - it's one or the other.
-craig

"You can never have too many knives" -- Logan Nine Fingers
davebert99
Participant
Posts: 9
Joined: Fri May 29, 2009 9:23 am

Post by davebert99 »

OK, I just tried it and I get a '3' exit code. When I fixed the error I get a '1' exit code - and not the standard '0' for good. I can live with this and program the script accordingly. So there is not a way to return standard exit codes of '0' for good and non-zero for bad? I assume I'll have to check for 1 for OK, 2 for warnings and 3 for abort? 1,2=good, anything else=bad.
chulett wrote:OK, good - now the Sequence is aborting as well and will return an exit status of "3" when using the -jobstatus option. If that's not what is happening, make sure you are using it by itself and not in conjunction with the -wait option - it's one or the other.
Post Reply