This document contains official content from the BMC Software Knowledge Base. It is automatically updated when the knowledge article is modified.
When our job fails it is automatically rerun via a DO RERUN statement, but after the job has been rerun 3 times we would like Control-M to send a shout/mail message, instead of issuing it every time the job fails.
Control-M/Server for Unix and Microsoft Windows
In Control-M version 8 a new parameter for DO statement : "Job's number of failures" has been introduced. An action can be added when the parameter reach a wanted value.
For versions prior than Control-M version 8 one of the following workarounds can be used:
- Choose Job Editing Form -> register "Steps"
- Add following statement
ON stmt=* code= RUNCOUNT>3
It is not possible to do this from one job, so a second monitor job is needed. Every time the first job fails it sets the value of a global autoedit variable to the order id of the failed job. The second job references the global autoedit variable and then checks the number of times the job has run using the command.
For Unix run:
For Windows run:
where 4 indicates that the job has been rerun 3 times.
When the monitor job ends with a return code of 0 then it has determined that the job has been rerun 3 times and will can send an appropriate shout/mail message.
In the attached draft the above command was run from a batch script, but it could be run as a command.
If using this solution on more than one job then it will be necessary to ensure the name of the global autoedit variable name is unique for each monitored job.