After wondering if the crontab process could be managed more easily, I decided to create a package in Python. I really wanted to name it "cronpy", but I changed it to "cronpi" because someone else had already registered it. cronpi is a package that registers the processes that are regularly executed on UNIX-based personal computers (linux / mac) in crontab. It works with Python 2 and 3.
It makes crontab processing ** easier to read **.
Installation
pip install cronpi
sample.py
#Package import
import cronpi
#Register the process to be executed every day at 5:30 pm
cronpi.run_every_day("/opt/backup.sh").on("5:30pm")
cronpi has the following functions.
SN | Function name | Description |
---|---|---|
1. | run_by_date | Date YYYY-MM-DD HH:Processing that can be executed by specifying mm |
2. | run_every_day | HH:Processing that can be done every day by specifying the time in mm |
3. | run_every_week | Processing that can be executed by specifying the day of the week name |
4. | run_every_month | Processing that can be executed by specifying a date |
5. | run_every_year | Processing that can be executed by specifying the name and day of the month |
6. | run_custom | "crontab -e"Processing that can be executed by specifying the contents of one line to be entered in |
The above function accepts two arguments. cronpi.XXXX(<command>, <isOverwrite=bool>?)
parameter | type | description |
---|---|---|
command | string | Commands to be executed regularly |
isOverwrite | bool | If false, always add a new job. Default is False |
If the command with the first argument already exists in the job and the second argument is isOverwrite = True, replace the existing content with the new content instead of the new job.
-Registration of processing to be executed by specifying a date
cronpi.run_by_date("/some/command").on("2020-10-20 5:30pm")
・ Registration of processing to be executed every day
cronpi.run_every_day("/some/command").on("5:30pm")
-Registration of processing to be executed on a specific day of the week
cronpi.run_every_week("/some/command").on("sunday", time="17:30")
・ Multiple days of the week can be specified
cronpi.run_every_week("/some/command").on(["sat", "sun"], time="5:30PM")
・ Registration of processing to be executed every month
cronpi.run_every_month("/some/command").on(10, time="17:30")
・ Multiple days can be specified
cronpi.run_every_month("/some/command").on([10,20], time="17:30")
-Registration of processing to be executed in a specific month
cronpi.run_every_year("/some/command").on("january", day=10, time="5:30am")
・ Registration for multiple months is possible
cronpi.run_every_year("/some/command").on(["jan", "oct"], day=10, time="5:30")
・ Custom registration
cronpi.run_custom("* * * * * /some/command")
You can get the list of current jobs as a List by using the "get_job_list" function.
cronpi.get_job_list()
Recommended Posts