command line trigger for job

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
prasson_ibm
Premium Member
Premium Member
Posts: 536
Joined: Thu Oct 11, 2007 1:48 am
Location: Bangalore

command line trigger for job

Post by prasson_ibm »

Hi all,
I have requirement where I need to trigger my job from enterprise scheduler. I am planning to design a wrapper shell scrip which is going to do below:-
1. Check the status of job (aborted, crashed, not compilter)
2.if 1 is true recompile and trigger a sequence
3. If 1 false trigger a job without compilation.
3. Capture return code.
4. If return code 1 or 2 then exit 0 else exit 100

Please let me know if my approach is correct.

Secondly, can I create only one shell script and pass different sequence names as a parameter to the job, because almost all my sequences have pre defined parameters and same kind of structure.

What if 100 sequnce triggered from one script,at one time, will it perform correct.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Pretty much everyone with an Enterprise Scheduler has a wrapper script that does the actual call to dsjob with whatever pre/post checks and activities are appropriate in their environment. Kenneth Bland posted a rather comprehensive one here back in the day, from what I recall.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Specifically, this post has his wrapper in it, should give you some ideas. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
FranklinE
Premium Member
Premium Member
Posts: 739
Joined: Tue Nov 25, 2008 2:19 pm
Location: Malvern, PA

Post by FranklinE »

That is precisely how we run in production here, using Control-M (shop standard) as the scheduler.

Our script is generic and passes any input parameters from CM that we care to provide. We don't query job status as you describe -- my design is standarized on checkpoints, and we import design and executable from the test server, no compiling in production -- and I would suggest you monitor job performance on multiple calls to the runtime engine. CM has significant elasped time overhead without adding other processes to the dsjob script.
Franklin Evans
"Shared pain is lessened, shared joy increased. Thus do we refute entropy." -- Spider Robinson

Using mainframe data FAQ: viewtopic.php?t=143596 Using CFF FAQ: viewtopic.php?t=157872
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

We used Control-M as well. Mine would query the job and status as a pre-check to ensure that the job both existed and was in a runnable state. There was no compilation done, anything that meant the job would not run would result in a fatal error. And yes, it also built -PARAM name/value pairs on the fly as needed.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Code to get job status

Code: Select all

JobStatus=`$DSPath/dsjob -jobinfo $ProjectName $JobName | head -1 | cut -d"(" -f2 | cut -d")" -f1` 
Mamu Kim
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Code to reset job based on job status:

Code: Select all

case $JobStatus in 
# -----------------------------------------------------------------
# 0 "Running" 
# -----------------------------------------------------------------
    0) 
        echo "ERROR: Job $JobName already running." 
        CatLogFunction
        exit 1
        ;; 
# -----------------------------------------------------------------
# Runnable Job Status (do nothing) 
#  1 "Finished" 
#  2 "Finished (see log)" 
#  9 "Has been reset" 
# 11 "Validated OK" 
# 12 "Validated (see log)" 
# 21 "Has been reset" 
# 99 "Compiled" 
# -----------------------------------------------------------------
    1|2|7|9|11|12|21|99) 
        : 
        ;; 
# -----------------------------------------------------------------
# NOT Runnable Job Status (reset job) 
#  0 "Running" 
#  3 "Aborted" 
#  8 "Failed validation" 
# 13 "Failed validation" 
# 96 "Aborted" 
# 97 "Stopped" 
# 98 "Not Compiled" 
# -----------------------------------------------------------------
   *) 
        echo "$DSPath/dsjob -run -mode RESET -wait -jobstatus $ProjectName $JobName" 
        $DSPath/dsjob -run -mode RESET -wait -jobstatus $ProjectName $JobName
        ResetReturnCode=$?
        if  (( $ResetReturnCode==21 ))
        then
            print
            print DataStage reset successfull for job: $JobName is $ResetReturnCode  
            print
        else
            print
            print DataStage reset failed for job: $JobName  
            print Return code for job reset is: $ResetReturnCode 
            print
            echo "ERROR: Unable to reset job $ProjectName $JobName"
            CatLogFunction
            exit 3
        fi
esac 
Mamu Kim
prasson_ibm
Premium Member
Premium Member
Posts: 536
Joined: Thu Oct 11, 2007 1:48 am
Location: Bangalore

Post by prasson_ibm »

Hi,
How can we know from command line if job exists or not?
if job is not compiled, -jobinfo gives me error like cant open job, so how can I handle these two scenarios before running.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

We used -jobinfo to do both. If my experience, if it throws an ERROR the job didn't exist. No ERROR, then look in the same output to see if it was RUNNING or FAILED and branch accordingly.

Thinking about this not sure we ever had a situation where the job was not compiled... but if there was, I for one would have been perfectly happy to fail the script rather than automatically compile anything. Can you post the jobinfo output for the two scenarios so we can see if there is a difference in the error that can be leveraged?
-craig

"You can never have too many knives" -- Logan Nine Fingers
prasson_ibm
Premium Member
Premium Member
Posts: 536
Joined: Thu Oct 11, 2007 1:48 am
Location: Bangalore

Post by prasson_ibm »

Hi,

I have written below code to check the pre status of job and rerun job.

Code: Select all

JOBSTATUS=`${EngineDir}/bin/dsjob -authfile /home/dsadm/pras/AuthFile.txt -jobinfo ${ProjName} ${JobName} 2>/dev/null|grep "Job Status"|cut -d':' -f2|cut -d'(' -f2|cut
-d')' -f1`
echo
echo "#######Pre validation to check status of job run####################################"
echo "Job status is ${JOBSTATUS}"
echo
case "$JOBSTATUS" in
        0)
                echo "Job is running!"
                exit 100
                ;;
        1|11)
                echo "Job finished a normal run or validation run with no warnings"
                ;;
        2|12)
                echo "Job finished a normal run or validation run with warnings"
                ;;
        21)
                echo "Job is in reset mode"
                ;;
        3|96|97)
                echo "Job failed or crashed or stopped need to reset"
                echo "##Resetting Job####################################"
${EngineDir}/bin/dsjob -authfile ${Dir}/AuthFile.txt -run -mode RESET -wait ${ProjName} ${JobName}
                ;;
        98)
                echo "Job has not been compiled"
                exit 100
                ;;
        99)
               echo "Job is NOTRUNNING ,Any other status"
               ;;
        *)
                echo "ERROR: Failed to open job!"
                exit 100
                ;;
esac


##########Rerun job#####################################
Your input will be appriciated if i have missed something.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

That seems... fine... if all it is doing is make sure things are ready to go as you have no actual RUN mechanism in there. Have you tested it with a non-existent job? Asking because I looked for 'ERROR' in the jobinfo output rather than any kind of status value. And just a side note if this ends up doing the actual run if it passes all of the checks - we found a need to wait a small amount of time post-RESET before issuing the RUN to avoid seeing a "bad state" error... 5 seconds worked for us in the Server world. YMMV.

Oh, and you'll need to check that the job RESET properly as well at some point.
-craig

"You can never have too many knives" -- Logan Nine Fingers
prasson_ibm
Premium Member
Premium Member
Posts: 536
Joined: Thu Oct 11, 2007 1:48 am
Location: Bangalore

Post by prasson_ibm »

Hi,

Yes i have tested with non exisence job,it goes to last part of case statement and it displays genric message in that case statement and exit from script with return code 100.

Code: Select all

sh test_script1.sh QA ValidTest


#######Pre validation to check previous status of job run####################################
Job status is

ERROR: Failed to open job!
Exiting..
Post Reply