Page 1 of 2

dsjob showing status code = 1

Posted: Tue Jul 26, 2005 4:38 pm
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.

Posted: Tue Jul 26, 2005 4:42 pm
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.

Posted: Tue Jul 26, 2005 4:58 pm
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.

Posted: Tue Jul 26, 2005 5:06 pm
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

Posted: Tue Jul 26, 2005 5:17 pm
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.

Posted: Tue Jul 26, 2005 5:47 pm
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.

Posted: Tue Jul 26, 2005 6:02 pm
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.

Posted: Tue Jul 26, 2005 9:52 pm
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.

Posted: Wed Jul 27, 2005 4:00 am
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.

Posted: Wed Jul 27, 2005 6:28 am
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.

Posted: Wed Jul 27, 2005 8:07 am
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.

Posted: Wed Jul 27, 2005 8:09 am
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.

Posted: Wed Jul 27, 2005 8:12 am
by chulett
Sorry, not off the top of my head. My DOS days were long ago and far away. :wink:

Posted: Wed Jul 27, 2005 9:21 am
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?.

Posted: Wed Jul 27, 2005 9:24 am
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.