Skip to content

How to trigger an action in On Do Action based of a text in the Job Log output

Normally we can trigger an On Do Action based on string found in the Job Output.
But we would like to do the same for a Job log, that feature doesn’t exist, but there is a way to make it working.
Let’s see how to proceed.

Introduction

For example: as a use case:
See the blog How to automate a kill of one or several executing jobs in AJF at specific Date/Time at once, when the a running job is killed in purpose with the ctmkilljob utility, the job ends with a NOTOK State (red).
The issue of that, if we manage a On-Do Action on NOTOK situations, those Actions will be triggered.
We can avoid triggering those On-Do Actions for this specific context (job killed) by following the procedure below.
In this example, we will re-use the same case which is to automate a Kill of a job from another job:

Preparation

Define 2 jobs

  • Ctmtst-Job-Killer: Job which runs ctmkilljob utility to end another job

  • With PARM1= Ctmtst-To-Kill

  • Ctmtst-To-Kill: Job with short name to be killed but should end OK
    => Its Output should contain the text in the script
  • After running the jobs, t1ctmtst-To-Kill ends NOTOK as expected, and might trigger an unwanted ON DO ACTION if a NO OK is monitored

    See below Job log

    22:36:08 1/23/2022     STARTED AT 20220123223607 ON ctmsrv.domain.com      5101
    22:36:08 1/23/2022     JOB STATE CHANGED TO Executing  5120
    22:36:26 1/23/2022     JOB KILLED BY USER [email protected]   5409
    22:36:27 1/23/2022     ENDED AT 20220123223627. OSCOMPSTAT 1. RUNCNT 1   5100
    22:36:27 1/23/2022     Message from Agent: /opt/cmagt/ctm/sysout/Ctmtst_To_Kill.LOG_00iyte_00001   5169
    22:36:27 1/23/2022     ENDED NOTOK. NUMBER OF FAILURES SET TO 1     5134
    

    As we wanted to kill the job in purpose, then we would like to trigger the Set To OK in On Do Action

  • Solution

    1. Capture the Job log with the ctmlog command, the result will be append to the Job ouput
      • ctmlog listord %%ORDERID %%DATE 0000 %%DATE 2359
        

        The job output will contain its regular output and at the end also the job log as the result of ctmlog command

        + echo Start Job
        Start Job
        + sleep 300
        Date: 23-01-2022.   Page: 1
        Date: 23-01-2022.   Page: 1
        
            CTMLOG REPORT from 20220123 000000 to 20220123 235959
        
        Orderno : 0iyte (*884930)
        
        +-------------------------------------------------------------------------------------------------
        |Date|Time|Jobname              |Order|SS|MID |Message
        +-------------------------------------------------------------------------------------------------
        |0123|2236|Ctmtst-To-Kill_1     |0iyte|CS|5065|ORDERED JOB:31790; DAILY FORCED, ODATE 20220123
        |0123|2236|Ctmtst-To-Kill_1     |0iyte|SL|5105|SUBMITTED TO [email protected]
        |0123|2236|Ctmtst-To-Kill_1     |0iyte|TR|5101|STARTED AT 20220123223607 ON [email protected]
        |0123|2236|Ctmtst-To-Kill_1     |0iyte|TR|5120|JOB STATE CHANGED TO Executing 
        |0123|2236|Ctmtst-To-Kill_1     |0iyte|UT|5409|JOB KILLED BY USER [email protected]
        
    2. Last step, is to define the On Do Action Set to OK for this specific context (Job KILLED)
      • On Do Action definition
      • The Job will end OK and the log will contain
      • final state

      Enjoy 🙂

    Let’s work together

    Ready to operate at
    the next level?

    Tell us about your challenge. We’ll bring the depth, the expertise, and the Swiss precision.

    Microsoft Team

    Microsoft Team

    Posts published under the Microsoft Team account are collective contributions by the dbi services Microsoft consultants. The practice covers SQL Server across its lifecycle, from installation, migration, and security to high availability with Always On and performance tuning, together with Azure data services and the Microsoft Business Intelligence stack, including Power BI. The team holds Microsoft certifications up to Expert level and operates customer platforms under service level agreements.View Author posts

    263 posts since October 2011

    Most read in Control-M

    The Control-M posts our readers open most: the all-time favourites, and what is trending right now.

    1 thought on “How to trigger an action in On Do Action based of a text in the Job Log output”

    1. I tried this solution but ctmlog command in the post-execution field is not working. Ctmlog is not being recognize. Do you have to configure anything else to make it working?

    Leave a Comment

    Your email address will not be published. Required fields are marked *