Before we get to details of how CRON jobs can be monitored let’s first understand what exactly are CRON jobs.
What is CRON job?
A cron job is a Linux command that is used to schedule tasks to be executed in future. It is normally used to schedule a job that is executed periodically – for example, to send out a notification everyday.
For most cron jobs, there are three components present:
- The script that is to be called or executed.
- The command that executes the script on a reoccurring basis (setup in Crontab).
- The action or output of the script, which depends on what the script being called does. Scripts called as cron jobs can do anything ranging from updating databases to sending out email, sms notifications.
Tracking / Managing CRON jobs
When we setup CRON jobs, an important part of the process is to be able to check if the job is running successfully or it failed. If it failed, you would need to be notified at the earliest and may need to know the reason to fix the same quickly. When the job is running successfully, you would want to be aware of time a CRON job is taking to complete so that you can plan infrastructure, frequency etc for running the job. CRON jobs provides multiple ways to track the same. Below are some of the major ways to track these:
- Logging: Some details of the CRON job processing is logged in the Linux system logger. For Ubuntu systems, the start of all CRON jobs is logged and errors are logged irrespective of this setting. This default setting can, however, be modified to log any other detail by setting -L (loglevel) as the sum of following values.
- Sending Email: CRON daemon uses the Mail Transfer Agent (MTA) to send error reports. It can be configured to send emails to any desired email address. As soon as there is any error in the CRON job processing an email is sent with all the details. In case MTA is not setup on the system, “No MTA installed, discarding output” message shows up in the system log.
- Third party solutions: Apart from Logs and Emails there are various third-party solutions that allow you to track the CRON jobs. Most common solutions involve editing the crontab to add a command that would ping a third-party system to log the completion of CRON job. Then based on the status the third-party system can send you a real time notification indicating success / failure of job. For example, you may need to modify the job
* * * * * /home/user/run_backup.sh
to
* * * * * /home/user/run_backup.sh && curl https://third-party-server.com/some-uuid-here“
Drawback / Limitations of current solutions
The current solutions that we have available for tracking CRON jobs have multiple limitations that make it difficult to get sufficient information. Some of those are:
- There is no way to get a complete, updated list of CRON jobs from the server, unless, you login to the server and pull it out. And you need to do it on a regular basis as it is with every evolving system, CRON jobs keep getting added / removed.
- While preparing the list of CRON jobs you may also want to note their running schedule.
- If you are not using third party systems, it is almost impossible to maintain historical data of how much time a CRON job takes to complete and how this time varies overtime.
- The way third-party systems work, you will need add a command for all the CRON jobs you want to track. In case the additional command is missed for a job you will never get any details. Every time someone is setting up a job they need to be cautious and test that the setup is working fine.
How G8keeper manages CRON jobs
At G8Keeper we believe in making things as automated as possible. Most of the tedious human job we have automated so to eliminate mistakes and save time. So in line with that philosophy we ensure that no setup is needed to be done on per job basis, there is just a onetime setup that needs to be done on the server. G8Keeper tracks all the jobs setup on the server by default. Not only that it also provides you with a list of all the CRON jobs setup on the server but all the historical execution details of the job and timely alerts as well. Below are some details of the same:
- G8Keeper provides you a complete list of all the CRON jobs configured on the server. You can edit this list to add Name / Description for the job, so it makes more sense to anyone looking at the list. Also, the name added here is used in notifications that are sent.
- As you would notice, even at the top level, G8Keeper clearly shows the time for last run of the job, and if it was successful or failed. Alongside it shows the schedule of the job and which user was used to set it up.
- Execution details of the job shows Start | End time of the job, if the job was successful or failed. In case the job failed, it also shows the exit code so that developer can fix it quickly based on that.
We understand that no one method is superior or inferior for everyone. Our philosophy at G8Keeper is to automate everything that can be automated so that developers have time to do what they do best, at the same time, get all the information needed for system debugging if the need arises. If you like what you saw, then do give G8keeper a try and we are sure you will love it!