Capturing Script Output in After Job sub routine

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
punit
Participant
Posts: 16
Joined: Fri Nov 23, 2007 11:44 pm

Capturing Script Output in After Job sub routine

Post by punit »

Hi All,

I am calling a Unix script in the After job Sub routine of my data stage job.
Is there anyway i can capture the output returned from the script and abort the job and send a notification, in case the script did not executed correctly. ( return non zero outout)

Thanks in advance,
Punit
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

If the after-job script returns an error code then the job's status is set to aborted.
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

How you calling that script from the routine?

Capturing ScreenIO returning Errorcode should give you output in variable ScreenIO and the return code in ErrorCode.

EDIT: if errorcode is not zero, the job will abort.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

The abort part is automatic, if you really want the notification part you'll need a different mechanism to run the script (custom routine) which checks and emails itself. Then you can decide how the routine exits, if it aborts the job or not.
-craig

"You can never have too many knives" -- Logan Nine Fingers
punit
Participant
Posts: 16
Joined: Fri Nov 23, 2007 11:44 pm

Post by punit »

ArndW wrote:If the after-job script returns an error code then the job's status is set to aborted. ...
My script is running db2 statements to insert records into table. One of the insert statement did not executed correctly.
Although i am able to see the output of the script in the Dsta Stage director log, but the job did not aborted
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Then your script is faulty and not properly communicating the error back up to the calling process. It will need to exit with a non-zero status when there is a problem detected.
-craig

"You can never have too many knives" -- Logan Nine Fingers
punit
Participant
Posts: 16
Joined: Fri Nov 23, 2007 11:44 pm

Post by punit »

priyadarshikunal wrote:How you calling that script from the routine?

Capturing ScreenIO returning Errorcode should give you output in variable ScreenIO and the return code in ErrorCode.

EDIT: if errorcode is not zero, the job will abort.
I am calling the script by using Afetr Job subroutine (ExecSH) option in Job properties. I just need to capture the return code of this script. Its possible to capture this code, if we use ExecActivity stage in the sequencer, but my task is to capture this output in the job and not sequencer
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ahem... your script is faulty, as in lacking in functionality. Doesn't matter how / where you run it, you need to 'fix' it first regardless.
-craig

"You can never have too many knives" -- Logan Nine Fingers
punit
Participant
Posts: 16
Joined: Fri Nov 23, 2007 11:44 pm

Post by punit »

Although the script will always return a non zero value on unsuccessfull execution, I will try to explicitly return non zero exit status after each statement in script. But it seems to be a lengthy solution.

shorter solution is welcome :)
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Well, there's "lengthy" and then there's "proper". If this is anything like how I'd have to do it in Oracle, the script is calling the command line interface to the database - for Oracle that would be sqlplus. Once inside sqlplus, it would then run whatever DML/DDL statements are required.

Without help from you, the script will "always return a non-zero value" if it cannot launch the command line interface. Period. Once inside that, any sql failures will go unnoticed unless you specifically do something to capture and interrogate them and - when you find a problem - set the script to exit with a non-zero status after the db session ends. And it certainly doesn't take checking after every statement in the script to accomplish that.

Now, if DB2 is somehow completely different, then all my words of wisdom are for naught. :(
-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 »

DB2 is exactly the same except for the name of the command which, unsurprisingly perhaps, is "db2".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply