dsjob showing status code = 1

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

I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

dsjob showing status code = 1

Post by I_Server_Whale »

Hi All,

I have a written a small batch script which runs a job and returns the status. The batch script is as follows;

Code: Select all

e:\ascential\datastage\engine\bin\dsjob -run -jobstatus dev SVR_INVDPT_HASH
And it returns:

Code: Select all

Finished waiting for job

          Status Code = 1
Why is it returning 1? Shouldn't it return 0 if a job is finished successfully?

If I run the job without the "-jobstatus" then it returns the Status Code as 0.

Please help me out!. Thanks much!

Naveen.
pnchowdary
Participant
Posts: 232
Joined: Sat May 07, 2005 2:49 pm
Location: USA

Post by pnchowdary »

Hi NaveenD,

I believe that the jobstatus return code is 1 for success and 2 for finished with warnings etc. When you remove -jobstatus option from your dsjob command, I think its returning the return code of the dsjob command execution and not the actual jobstatus, in which success is 0 and failure is 1.
Last edited by pnchowdary on Tue Jul 26, 2005 5:01 pm, edited 1 time in total.
Thanks,
Naveen
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Hi Naveen,

When it returns the status 0, does this mean that datastage is returning the status code to the calling batch script? If so, how do I capture this Status info. I tried "> status.txt" but an empty file is being created.

Actually, we want to use CNTRL-M to schedule the jobs. So, when we run these jobs thru batch scripts, CNTROL-M should be able to pick up the status code.

Once again, Thanks a zillion for your help,

Naveen.
pnchowdary
Participant
Posts: 232
Joined: Sat May 07, 2005 2:49 pm
Location: USA

Post by pnchowdary »

Hi NaveenD,

Yes, it returns the return code to the calling batch script. In the batch script you can capture this return code using $?

Code: Select all

MyRetCode = $?
You might also want to refer to this thread viewtopic.php?t=94175
Thanks,
Naveen
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Hi Naveen,

I have tried it but I got an error. This is how my batch file looks:

Code: Select all

e:\ascential\datastage\engine\bin\dsjob -run -jobstatus dev SVR_INVDPT_HASH
MyReturnCode = $?
It did run the job successfully. But it gave me this error message.

Code: Select all

Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\Documents and Settings\ndrovall>e:\tmp\cusa_jda_prod.bat

C:\Documents and Settings\ndrovall>e:\ascential\datastage\engine\bin\dsjob -run -jobstatus dev SVR_INVDPT_HASH
Waiting for job...
Finished waiting for job
Job Status      :  (1)

Status code = 1

C:\Documents and Settings\ndrovall>MyReturnCode = $?
'MyReturnCode' is not recognized as an internal or external command,
operable program or batch file.

Where am I going wrong? Any idea? Help me out! Can't express my gratefulness. Thanks so much,

Naveen.
pnchowdary
Participant
Posts: 232
Joined: Sat May 07, 2005 2:49 pm
Location: USA

Post by pnchowdary »

Hi NaveenD,

I was referring to $? as the parameter that returns the return code in UNIX. I am not sure of the WINDOWS equivalent. Maybe the Gurus can help us both in this matter.
Thanks,
Naveen
pnchowdary
Participant
Posts: 232
Joined: Sat May 07, 2005 2:49 pm
Location: USA

Post by pnchowdary »

Hi NaveenD,

Try using this

Code: Select all

@ECHO OFF
IF ERRORLEVEL 1 SET ERRORLEV=1
IF ERRORLEVEL 2 SET ERRORLEV=2
IF ERRORLEVEL 3 SET ERRORLEV=3

ECHO %ERRORLEV%
or simply for display

Code: Select all

ECHO %ERRORLEVEL%
you need to modify it based on your requirement

I am not sure how well this works, but this might work for you. Give it a try.
Thanks,
Naveen
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Status 0 means "running".
All the status codes are documented in JOBCONTROL.H, which you will find in a subdirectory called dsinclude in your project.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
dsxdev
Participant
Posts: 92
Joined: Mon Sep 20, 2004 8:37 am

Post by dsxdev »

Hi,
Return code $? will return 0 if the command dsjob is successful and would return non zero when it fails.
You do not get the status of job.
For this once you run the command.
You can run the dsjob -jobinfo and check the job status.
this would give you the job status exactly.

you can try this
run the job

Code: Select all

/apps/Ascential/DataStage/DSEngine/bin/dsjob -jobinfo $Project $JobName 
Then execute dsjob command again for the same job to check if the job failed or not in runnable state.

Code: Select all

/apps/Ascential/DataStage/DSEngine/bin/dsjob -jobinfo $Project $JobName | grep -E "RUN FAILED|Job Status : NOT RUNNING"
Then you send abort signal to CNTRL-M.
When ever you run the dsjob command it only echos the job status not job return code.
Happy DataStaging
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

dsxdev wrote:When ever you run the dsjob command it only echos the job status not job return code.
Not really, the behaviour depends on the command line options you choose. Assuming you are wanting to wait for the job to actually finish before moving on to the next step in your script, it works one of two ways:

Code: Select all

-wait        Returns a 0 or non-zero code

-jobstatus   Returns the DataStage Job Status code (1,2,3,etc)
So, there's no need to poll the job after it finishes to check the 'job status'.

I also seem to recall that the -wait option always returns a zero if the job was started (i.e. 'run') regardless of the outcome of that run. In other words, an aborted job would report back a zero code as it was able to start. Non-zero codes would be returned when a job name cannot be found or the job cannot otherwise be started.

We use -jobstatus exclusively. I'd need to run some tests to validate the operation of the -wait option.
-craig

"You can never have too many knives" -- Logan Nine Fingers
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Hello Craig,

Thanks for the information and timely help. I will use -jobstatus to get the return code by datastage after the job has finished. But how do I capture this code if I'm using a batch file to run the job?

How do I capture the exit code to text file? Any help would be tremendously appreciated.

Thanks again,
Naveen.
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Hello Craig,

I'm using windows and a DOS batch file. I don't have much grasp on DOS. I know we can capture the exit code by using $? in UNIX.
But what about DOS?

Hoping for the best,
Naveen.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sorry, not off the top of my head. My DOS days were long ago and far away. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
pnchowdary
Participant
Posts: 232
Joined: Sat May 07, 2005 2:49 pm
Location: USA

Post by pnchowdary »

Hi NaveenD,

Did you try the %ERRORLEVEL% return code that I mentioned earlier in the same post?. If you tried, can you please tell me what was the result of it?.
Thanks,
Naveen
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Hi Craig,

No problemo. Take it easy. But thanks for all your valuable help. I actually got my script working with pnchowdary's reply to this post.

Thanks again, :)
Naveen.

Hi pnchowdary,

Thanks a million! I have successfully captured the exit code to a text file with little modification to code you last posted. Thanks man!
:)
Naveen.
Post Reply