[LINUX] Manage cron jobs with python

Build Statuspypi GitHublicense

What is cronpi

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

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")

List of Functions

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.

How to use

① Process to be executed only once

-Registration of processing to be executed by specifying a date

cronpi.run_by_date("/some/command").on("2020-10-20 5:30pm")

② Processing to be executed every day

・ Registration of processing to be executed every day

cronpi.run_every_day("/some/command").on("5:30pm")

③ Process to be executed every week

-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")

④ Processing to be executed every month

・ 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")

⑤ Processing to be executed every year

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

・ Custom registration

cronpi.run_custom("* * * * * /some/command")

Supplement

You can get the list of current jobs as a List by using the "get_job_list" function.

cronpi.get_job_list()

Recommended Posts

Manage cron jobs with python
Manage python environment with virtualenv
[Package cloud] Manage python packages with package cloud
Manage each Python version with Homebrew
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Execute Python script with cron of TS-220
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Manage multiple Python versions with update-alternatives (Ubuntu)
Excel with Python
Microcomputer with Python
Cast with python
AWS-Perform web scraping regularly with Lambda + Python + Cron
Manage Python multiple version environment with Pythonz, virtualenv
Manage AWS nicely with the Python library Boto
Manage multiple context managers together with Python contextlib.ExitStack
Serial communication with Python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Socket communication with Python
Data analysis with python 2
Scraping with Python (preparation)
Try scraping with Python.
Learning Python with ChemTHEATER 03
"Object-oriented" learning with python
Run Python with VBA
Handling yaml with python
Solve AtCoder 167 with python
Serial communication with python
[Python] Use JSON with Python
Learning Python with ChemTHEATER 05-1
Learn Python with ChemTHEATER
Run prepDE.py with python3
1.1 Getting Started with Python
Collecting tweets with Python
Binarization with OpenCV / Python
3. 3. AI programming with Python
Kernel Method with Python
Non-blocking with Python + uWSGI
Scraping with Python + PhantomJS
Posting tweets with python
Drive WebDriver with python
Use mecab with Python3
[Python] Redirect with CGIHTTPServer
Voice analysis with python
Think yaml with python
Operate Kinesis with Python
Getting Started with Python
Use DynamoDB with Python