Page 1 of 1

command line trigger for job

Posted: Thu Jun 12, 2014 12:15 am
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.

Posted: Thu Jun 12, 2014 12:19 am
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.

Posted: Thu Jun 12, 2014 6:46 am
by chulett
Specifically, this post has his wrapper in it, should give you some ideas. :wink:

Posted: Thu Jun 12, 2014 9:25 am
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.

Posted: Thu Jun 12, 2014 9:35 am
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.

Posted: Fri Jun 13, 2014 7:38 pm
by kduke
Code to get job status

Code: Select all

JobStatus=`$DSPath/dsjob -jobinfo $ProjectName $JobName | head -1 | cut -d"(" -f2 | cut -d")" -f1` 

Posted: Fri Jun 13, 2014 7:39 pm
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 

Posted: Sat Jun 14, 2014 2:19 am
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.

Posted: Sat Jun 14, 2014 7:03 am
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?

Posted: Mon Jun 16, 2014 8:43 am
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.

Posted: Mon Jun 16, 2014 9:03 am
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.

Posted: Mon Jun 16, 2014 9:33 am
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..