Introduction

We had a request to automate a kill of some executing jobs in AJF at specific date and time.

For example:
A Control-M job is running a script all day, in order other programs can connect to it, but the script has to be stopped at a specific time.

There are several ways to manage that, such as:

  • using in Action Tab, use Notifications before job completion, then run a Shout to a script which kills the Job with its %%ORDERID as parameter:
  • Run a separate job which runs a script which does a Unix command Kill -9 of the script
  • This new way which is also to run a separate job which runs a script which uses the native kill feature of Control-M (ctmkill utility), but it can be used to Kill one or several jobs at once, based on the list of Jobs name
    => This last method will be described here

For that we need

  • a script (in Unix) which will run the ctmkill utility for 1 or several Job names which are in Executing mode
  • A Control-M job which launches the script, passing as parameter the list of jobs to be killed
    That Job is scheduled at the wished date & time
  • In some contexts, we need to pay attention on some prerequisites (Job name, type of agent, Control-M security)

Job definition

For this use case, there are Jobs:

  1. Job_Killer


  2. Define in PARM# list of Jobs name to Kill

  3. Two Jobs to kill : Job_To_Kill_1 and Job_To_Kill_2
  4. Running Jobs in AJF

Unix script

$HOME/My_Scripts/kill_job_by_jobname.sh

# Description: kill one or several Control-M executing Jobs by using ctmpsm and ctmkill Control-M utilities
#  Parameter: 1 or several Job name from PARAM#
#
echo The number of daemon to kill is $#
echo jobname $1
if [ -z "$1" ]
then
   echo A jobname is required as first parameter
   exit 101
else
  echo Jobname : $1
fi

# for each parameter
until [ $# = 0 ]
do
  echo Parameter value : $1
### When using the ctmpsm utility of an Control-M agent, the separator is “pipe |” for awk
  export OrderId=`ctmpsm -LISTALL | grep $1 | grep Executin |  awk -F" " '{print $1}'`
#
### When using the ctmpsm utility of the Control-M server, the separator is “space |” for awk
#  export OrderId=`ctmpsm -LISTALL | grep $1 | grep Executin |  awk -F"|" '{print $1}'`
  echo The orderId for $1 job is : $OrderId

  # Get the number of order id in result
  num_OrderId=`echo $OrderId | awk  '{print NF}'`
  echo The number of order id is : $num_OrderId

  # If no order id
  if [ -z "$OrderId" ]
  then
    echo No OrderId found. No kill will happen for $1.
    #echo No OrderId found. EXIT 102.
    #exit 102

  # If more than one order id
  elif [ $num_OrderId -gt 1 ]
  then
    echo There is more than one order id : $num_OrderId. No kill will happen for $1.
    #echo There is more than one order id : $num_OrderId. EXIT 103.
    #exit 103

  # Else display and kill the job
  else
    echo Parameter value is : $1.
    echo The order number is : $OrderId
    ctmkilljob -ORDERID $OrderId
  fi
  shift
done



Pre-requisites

  1. Job name issues
    • Length
      It must be up to 18 characters, because the ctmpsm displays 18 characters
    • Similar Name
      There should be no other existing running job which name starting with the same name, otherwise that job will be taken in account
      For example:
      Job executing to kill : Job_123
      Another job executing : Job_123_To_no_Kill
      => That could be confusing because both jobs will be found in the pattern then it will fail
  2. Control-M Security

    If Control-M Full Security (ctmsys) is set to Y, as the Agent is running the ctmkill utility, ensure that agent is defined in ctmsec as a User, and it has the permission in AUTHORIZED AJF Tab, The Kill option set to Yes

    Otherwise you’ll get such error in the Output

  3. ctmpsm utility

    This utility is used to list all jobs in the AJF
    It exists in Control-M/Server installation and also in Control-M/Agent installation, but the Output is slightly different, and then has an impact of the awk command within the script

    • ctmpsm of Control-M Server

      The separator is a space “ “

    • ctmpsm of Control-M Agent

      The separator is a pipe “| “

=> In the script, with the awk command, indicate the appropriate separator :
awk -F” “ or awk -F”|”