Page 1 of 2

dsjob has status=0 even though job aborts

Posted: Tue Jul 28, 2009 2:48 pm
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

Posted: Tue Jul 28, 2009 3:04 pm
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.

Posted: Tue Jul 28, 2009 4:24 pm
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.

Posted: Tue Jul 28, 2009 4:44 pm
by chulett
And then they'll always get a one rather than a zero. :wink:

Posted: Tue Jul 28, 2009 4:54 pm
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.

Posted: Tue Jul 28, 2009 4:57 pm
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

Posted: Tue Jul 28, 2009 5:25 pm
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

Posted: Tue Jul 28, 2009 6:50 pm
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]

Posted: Wed Jul 29, 2009 6:39 am
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 ...

Posted: Wed Jul 29, 2009 6:42 am
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.

Posted: Wed Jul 29, 2009 6:51 am
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. ...

Posted: Wed Jul 29, 2009 7:04 am
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.

Posted: Wed Jul 29, 2009 7:18 am
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. ...

Posted: Wed Jul 29, 2009 7:32 am
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.

Posted: Wed Jul 29, 2009 7:41 am
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.