How to Monitor Cronjob Execution Status Using Nagios

Administrator has best option to automate there jobs by scheduling script using crontab/ cronjobs. You have scheduled an important and CRITICAL job on crontab but do you know is it run successfully or struck in the middle.? So Let’s see monitor cronjob execution status Using Nagios.

Download Nagios Plugin and copy to your Nagios server machine

How to Monitor Cronjob execution status Using Nagios – How it Works.?

Script checks exit code (number) and based on that it will tell that cronjob is executed perfectly or not. To capture each and every cronjob exit code we have to add below redirection to cronjob ending

2>&1 > /var/log/cronjobname.log; echo "Exit code: $?" >> /var/log/cronjobname.log
  • 2>&1 –> Send standard error to where ever standard output is being redirected as well.
  • $? –> Return code from the last command
# tail -f /var/log/whichbig.log
6 is big than 5
Exit code: 0

Sample log file output

Setup Nagios Plugin

Usage of check_exit_code plugin is below

#/usr/local/nagios/libexec/ --help

 Check log output has been modified with t minutes and contains "Exit code: 0".
 If "Exit code" is not found, assume command is running.
 Check assumes the log is truncated after each command is run.

 --help shows this message
 --version shows version information
 -f path to log file
 -t Time in minutes which a log file can be unmodified before raising CRITICAL alert


/usr/local/nagios/libexec/ -f <log file path> -t <time in minutes>


#/usr/local/nagios/libexec/ -f /var/log/test.log -t 10
OK. Command completed successfully about 1.58 minutes ago.

#/usr/local/nagios/libexec/ -f /var/log/test.log -t 1
CRITICAL. ERROR: /var/log/test.log last modified 3.55 minutes, threshold set to 1 minutes

Define command in commands.cfg file 

define command {
command_name check_exit_code
command_line $USER1$/ -f $ARG1$ -t $ARG2$

Service definition is below 

define service{
 use local-service 
 host_name localhost
 service_description Cronjob Status
 check_command check_exit_code!/var/log/test.log!10

If you have multiple cronjobs to monitor then separate the log file names based on there script name so that it will be easy to identify

That’s it Nagios will automatically informs you about your cronjob execution status.

Related Articles

SNMP Linux Server Monitoring

NagiosXI Web Console Login Alert

NSP Sorry Dave error Resolution

Thanks for your wonderful Support and Encouragement

Ravi Kumar Ankam

My Name is ARK. Expert in grasping any new technology, Interested in Sharing the knowledge. Learn more & Earn More

5 Responses

  1. sid says:

    how to achieve the same using NRPE ? The plugin does not support NRPE it seems.

  2. Abhilasha Patil says:

    Can you post the link for plugin? Which port does it use?

  3. blank john says:

    How do you run this for a remote server?

    • blank ARK says:

      Add config in NRPE file and copy the script to remote server /usr/local/nagios/libexec loccation. Nagios will execute the remote script using NRPE client.

  4. blank Aditya Sharma says:

    i understood that i need to add command definition in commands.cfg but where to add this service definition, do i have to create a services.cfg file

Leave a Reply

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