dsjob (status code)

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

mystuff
Premium Member
Premium Member
Posts: 200
Joined: Wed Apr 11, 2007 2:06 pm

dsjob (status code)

Post by mystuff »

I have a code as below to obtain the latest event.

On the terminal I obtain Status Code = 0

and appropriate value gets assigned to variable $id

Code: Select all

id=`dsjob -lognewest $Project $Job | cut -d"=" -f2`
Q1) What do I do if I don't want that Status Code = 0 to be displayed at the terminal. I tried >/dev/null. But when I use this, the $id doesn't get variable assigned to it.

Q2) At the same time, how do I check the returned values and know whether the dsjob command was successful or failed + where can I find list of returned values (I looked at the documentation and wasn't able to find it) .
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

How about just redirecting everything, try

Code: Select all

id=`dsjob -lognewest $Project $Job 2>&1 | cut -d"=" -f2`
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Add -jobstatus to your command line so you get more information on the status of the job. Look in $DSHOME/include/dsapi.h for the error codes to check for:

Code: Select all

/* 'jobStatus' values... */

#define DSJS_RUNNING            0       /* Job running */
#define DSJS_RUNOK              1       /* Job finished a normal run with no warnings */
#define DSJS_RUNWARN            2       /* Job finished a normal run with warnings */
#define DSJS_RUNFAILED          3       /* Job finished a normal run with a fatal error */
#define DSJS_VALOK              11      /* Job finished a validation run with no warnings */
#define DSJS_VALWARN            12      /* Job finished a validation run with warnings */
#define DSJS_VALFAILED          13      /* Job failed a validation run  */
#define DSJS_RESET              21      /* Job finished a reset run */
#define DSJS_CRASHED            96      /* Job was stopped by some indeterminate action */
#define DSJS_STOPPED            97      /* Job was stopped by operator intervention (can't tell run type) */
#define DSJS_NOTRUNNABLE        98      /* Job has not been compiled */
#define DSJS_NOTRUNNING         99      /* Any other status */
And you don't need to capture and cut out that status that is echo'd to the screen, simply assign the status of the command itself (just like any other UNIX function) to a variable using $? and check that - or check it directly.
-craig

"You can never have too many knives" -- Logan Nine Fingers
mystuff
Premium Member
Premium Member
Posts: 200
Joined: Wed Apr 11, 2007 2:06 pm

Post by mystuff »

When I just try to run

Code: Select all

dsjob -lognewest $Project $Job 
I get two values displayed on the terminal

Code: Select all

Newest Id=....

Status Code=0
a) I wanted to suppress both from displaying to the output, looks like as mentioned by ArndW 2>&1 should take care about it.

b) I want to assign Newest Id to variable $Id

c) Based on the Status Code, I wanted to know if the above command has worked successfully. I don't want to check job status as I do that prior to calling the above command line.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sorry, misread what was going on here. Please feel free to ignore.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Mystuff - what was wrong with my suggestion? It worked on my system.
mystuff
Premium Member
Premium Member
Posts: 200
Joined: Wed Apr 11, 2007 2:06 pm

Post by mystuff »

ArndW
Mystuff - what was wrong with my suggestion? It worked on my system.
With the above command The variable Id is getting assigned with two values i.e. when I say

Code: Select all

eventid=`dsjob -lognewest $Project $Job 2>&1 | cut -d"=" -f2`
echo "$eventid"
Then I get

Code: Select all

841
0
The 0 (ie) the status code comes along with event id (841). I can do a grep to ignore the status code. But wanted to have value of event id in the variable + use the status code to verify if the command has worked properly (I already check status of the job before executing this command).
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

This is what I have used in the past and it works.

Code: Select all

dsjob -lognewest $Project $JobName | awk -F"\=" '{print $2}' | read EventId
Now when you echo EventId, you will have the event id, only.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
mystuff
Premium Member
Premium Member
Posts: 200
Joined: Wed Apr 11, 2007 2:06 pm

Post by mystuff »

dsjob -lognewest $Project $JobName | awk -F"\=" '{print $2}' | read EventId
Should I not deal with the status code. I mean if in case the command didnt execute properly for some reason (I do check the job status before running this command). Then what shall I check against?
mystuff
Premium Member
Premium Member
Posts: 200
Joined: Wed Apr 11, 2007 2:06 pm

Post by mystuff »

dsjob -lognewest $Project $JobName | awk -F"\=" '{print $2}' | read EventId
Should I not deal with the status code. I mean if in case the command didnt execute properly for some reason (I do check the job status before running this command). Then what shall I check against?
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Check the status with $?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
mystuff
Premium Member
Premium Member
Posts: 200
Joined: Wed Apr 11, 2007 2:06 pm

Post by mystuff »

Where can I check $? value against

I tried to look in $DSHOME/include/dsapi.h. But didn't know how to look at the returned code from dsjob -lognewest. Similarly I want to look for dsjob -logdetail etc..
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

You wont find the return code from any *.h file. Its standard unix command return code that the OS returns.
For examply, if I run a grep command, i will get a status code. 0 means all went well and the grep was successful in finding a string/character. 1 means no matches found. 2 means there were syntax errors. You can get this info by googling for "grep man".
Similarly different commands have different exit codes.
As I mentioned earlier, 0 usually means the command executed succesfully.
$? holds the exit status of the last executed command.
so for your command I would do something like

Code: Select all

eval dsjob -lognewest $Project $JobName | awk -F"\=" '{print $2}' | read EventId
              if [ $? -ne 0 ]
              then
                  echo "Error."
                  exit 2
              fi
.....Next command.......
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

So, feel free to not ignore the last paragraph in my reply. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
mystuff
Premium Member
Premium Member
Posts: 200
Joined: Wed Apr 11, 2007 2:06 pm

Post by mystuff »

In
dsjob -jobinfo $PROJECT $JOB

command returning
0 - the job is still running
1 - Finished
2 - Finished (see log)
etc...

How is the above code different than the below i.e. don't we have list of anything as that sort for the below commands

Code: Select all

dsjob -logdetail $PROJECT $JOB
dsjob -lognewest $PROJECT $JOB
Post Reply