GithubHelp home page GithubHelp logo

cron-monitoring's Introduction

Cron Monitoring

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.

MIT License

  1. Installation
  2. API Reference
  3. What are cron jobs?
  4. Creating new jobs.
  5. Cron jobs syntax.
  6. Acknowledgements

Installation

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.

API Reference ๐Ÿš€

Get all jobs

  GET /jobs

Create new job

  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 a job

  DELETE /job
Parameter Type Description
id string Required. The internal job ID.

What are cron jobs?

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.

Creating new cron jobs

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.

Cron jobs syntax

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 or 7 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

Cron Jobs Examples

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

Acknowledgements

More info about Crontab

Flask API in Python

cron-monitoring's People

Contributors

treeindev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.