Cron Jobs Test

Cron is a time-based scheduling service, and is hence considered to be a convenient mechanism for running critical jobs. On Solaris, to track when and how the scheduled jobs ran, you can enable the logging of cron jobs. Subsequently, a log file is created in the /var/cron/log directory, to which every cron activity is logged.

In other Unix (non-Solaris) hosts however, to enable cron logging, you have to do the following:

  1. Create a separate wrapper script to execute each cron job. This script should also track the status, start time, and end time of the cron job. For example, given below is a sample wrapper script named wcron2.sh.

    #!/bin/sh

    echo "Started Wrapper script - $0 - at `date` - $$"

    ’’ Cron Command here.

    echo "Exit Code for - $0 is - $? - $$"

    echo "Completed Wrapper script - $0 - at `date` - $$"

  2. Schedule the wrapper script to run at the same frequency in which you want the corresponding cron job to run. When doing so, make sure that the wrapper script outputs a log file, which will contain the start time, completed time, the script name and the status of the cron job. To achieve the above, use the following command:

    */10 * * * * /tmp/wcron2.sh >> /var/log/wcron2.log 2>&1

    Here, 10 indicates that the wrapper script should run every 10 minutes. You can provide any value (in minutes) here to indicate the frequency of the cron job. 

    /tmp/wcron2.sh is the full path to the wrapper script that has to be run at the specified frequency

    /var/log/wcron2.log is the full path to the log file (wcron2.log) to which the status, start time, end time, and cron job name have to be written.

    Note:

    The log file should have the same name as the wrapper script that creates it.  For instance, if the wrapper script is named wcron2, the corresponding log file should be named wcron2.log

    >> symbol indicates that every time the wrapper script runs, the log file contents will be overwritten.

  3. The contents of the log file will be similar to the same cited below:

    Started Wrapper script - /tmp/cronjob.sh - at Thu Oct  3 17:24:01 IST 2013 - 21946

    cronjob .sh

    Exit Code for - /tmp/cronjob.sh is - 0 - 21946

    Completed Wrapper script - /tmp/cronjob.sh - at Thu Oct  3 17:24:01 IST 2013 - 21946

Once the cron log file is available, you can periodically track the success/failure of the scheduled cron jobs by executing the Cron Jobs test. This test checks the cron log file at configured intervals and reports the status of the cron jobs.

This test is disabled by default. To enable the test, go to the enable / disable tests page using the menu sequence : Agents -> Tests -> Enable/Disable, pick the desired Component type, set Performance as the Test type, choose the test from the DISABLED TESTS list, and click on the << button to move the test to the ENABLED TESTS list. Finally, click the Update button.

Target of the test : Any Unix host

Agent deploying the test : An internal agent

Outputs of the test : One set of results for the host monitored

Configurable parameters for the test
Parameter Description

Test Period

How often should the test be executed.

Host

The host for which the test is to be configured.

Logfilepath

This test monitors the cron log file to determine the status of the cron jobs. Therefore, in the LOGFILEPATH text box, specify the path to the folder that contains the cron log file to be monitored. On Solaris, by default, this will be /var/cron/log. On other Unix hosts, specify the log file location that you provided when scheduling the execution of the wrapper script (refer to step 2 of procedure discussed in page Schedule the wrapper script to run at the same frequency in which you want the corresponding cron job to run. When doing so, make sure that the wrapper script outputs a log file, which will contain the start time, completed time, the script name and the status of the cron job. To achieve the above, use the following command: above).

Detailed Diagnosis

To make diagnosis more efficient and accurate, the eG Enterprise embeds an optional detailed diagnostic capability. With this capability, the eG agents can be configured to run detailed, more elaborate tests as and when specific problems are detected. To enable the detailed diagnosis capability of this test for a particular server, choose the On option. To disable the capability, click on the Off option.

The option to selectively enable/disable the detailed diagnosis capability will be available only if the following conditions are fulfilled:

  • The eG manager license should allow the detailed diagnosis capability
  • Both the normal and abnormal frequencies configured for the detailed diagnosis measures should not be 0.
Measurements made by the test
Measurement Description Measurement Unit Interpretation

Scheduled jobs:

Indicates the number of jobs that are scheduled to run in the next measurement period.

Number

 

Outstanding jobs:

Indicates the number of jobs that were started but not completed during the last measurement period.

Number

This includes jobs that were started and those that were still executing during the last measurement period. A very high value could be a cause for concern, and might require further investigation.

Completed jobs:

Indicates the number of jobs that were completed during the last measurement period.

Number

 

Failed jobs:

Indicates the number of jobs that were completed during the last measurement period, but with errors.

Number

The error status could be due to permission issues, path issues, problem while executing the job itself, etc.

Max pending job time:

 

Indicates the maximum time for which the jobs have remained pending.

Mins

A very high value of this measure could indicate a problem condition.

Max completion time:

Indicates the maximum time taken by the jobs for completion.

Mins

A very high value of this measure could indicate a problem condition.

Avg pending job time:

Indicates the average time for which jobs have remained pending.

Mins

A very high value of this measure could indicate a problem condition.

Avg completion time:

Indicates the average time taken by the jobs for completion.

Mins

A very high value of this measure could indicate a problem condition.

Pending jobs:

Indicates the number of cron jobs that are scheduled, but are yet to start running.

Number