Cron Monitoring is a tool to manage Cron Jobs running on a Unix machine. It allows for remote access to active cron jobs, add new jobs or remove existing ones.
- Installation
- API Reference
- What are cron jobs?
- Creating new jobs.
- Cron jobs syntax.
- Acknowledgements
To install it you need to clone this repository into your destination serve, install dependencies and run the application server.
cd src/
pip3 install -r requirements.txt
python3 api.py
This tool is built on top of Python 3
. You can check Python Virtual Environments to work with multiple Python version on same machine.
The tool assumes you are running it on a serve with a web server like Apache, Nginx or similar. After running the api.py
script, CronMonitoring API will listen to localhost on port 5000
. You need to map that port listener to your own web server configuration.
To run unit test, run the following command: pytest
.
Important note: There is no user authentication on this version.
GET /jobs
POST /job
Parameter | Type | Description |
---|---|---|
minutes |
string |
Required. Which minutes to run the job. |
day |
string |
Required. Which days to run the job. |
month |
string |
Required. Which month to run the job. |
week_day |
string |
Required. Which days of the week to run the job. |
script_location |
string |
Required. The absolute folder path to the script. |
script_execution |
string |
Required. The commands that need to be executed to run the script. |
script_log |
string |
Required. Details about the output logs of running the script. |
DELETE /job
Parameter | Type | Description |
---|---|---|
id |
string |
Required. The internal job ID. |
A cron job allow you to run scheduled scripts at a given date and time. They are very helpful to execture routines periodically. Backups, data cleanup, send daily reports, check server availability or health checks are examples of Cron Jobs usecases.
To create new cron jobs you need to provide the following details:
minutes
, day
, month
, week_day
, script_location
, script_execution
, script_log
. This is the crontab job syntax generated by the CronMonitoring tool:
* * * * * cd {{script_location}} && {{script_execution}} >> {{log_output}}
Note: *
are replaced by provided datetime values.
This tool manages the creation of Cron Job behind scenes. However, here is the details of how these jobs look like. A typical Cron Job has the following syntax:
1 2 3 4 5 /path/to/script arg1 arg2
Where:
1
refers to Minute (0-59).2
refers to Hours (0-23).3
refers to Day (0-31).4
refers to Month (0-12) -12
being December.5
refers to Day of Week (0-7) -0
or7
being Sunday.path/to/script
refers to location of your script.
Here is the table for reference:
* * * * * script to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
For system jobs, a Cron Job also adds the USERNAME
of the user that will run the job.
1 2 3 4 5 USERNAME /path/to/script arg1 arg2
By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append >/dev/null 2>&1
. Example:
* * * * * /root/script.sh >/dev/null 2>&1
Run a job everyday at 3am:
0 3 * * * /root/job.sh
Run a job 5 minutes after midnight everyday:
5 0 * * * /root/job.sh
Run a python script first day of every month:
0 0 1 * * /root/job.sh