| single |
Python Crontab
--------------
Bug Reports and Development
===========================
Please report any problems to the [GitLab issues tracker]. Please use Git
and push patches to the [GitLab project code hosting].
**Note:** If you get the error got an unexpected keyword argument 'user'
when using CronTab, you have the wrong module installed. You need to
install ``python-crontab and not crontab`` from pypi or your local package
manager and try again.
Description
===========
Crontab module for reading and writing crontab files and accessing the
system cron
automatically and simply using a direct API.
Comparing the [below chart]
you will note that W, L, # and ? symbols are not supported as they are not
standard Linux or SystemV crontab format.
+-------------+-----------+-----------------+-------------------+-------------+
|Field Name |Mandatory |Allowed Values |Special Characters |Extra
Values |
+=============+===========+=================+===================+=============+
|Minutes |Yes |0-59 |\* / , - | < >
|
+-------------+-----------+-----------------+-------------------+-------------+
|Hours |Yes |0-23 |\* / , - | < >
|
+-------------+-----------+-----------------+-------------------+-------------+
|Day of month |Yes |1-31 |\* / , - | < >
|
+-------------+-----------+-----------------+-------------------+-------------+
|Month |Yes |1-12 or JAN-DEC |\* / , - | < >
|
+-------------+-----------+-----------------+-------------------+-------------+
|Day of week |Yes |0-6 or SUN-SAT |\* / , - | < >
|
+-------------+-----------+-----------------+-------------------+-------------+
Extra Values are '<' for minimum value, such as 0 for minutes or 1 for
months.
And '>' for maximum value, such as 23 for hours or 12 for months.
Supported special cases allow crontab lines to not use fields.
These are the supported aliases which are not available in SystemV mode:
=========== ============
Case Meaning
=========== ============
@reboot Every boot
@hourly 0 * * * *
@daily 0 0 * * *
@weekly 0 0 * * 0
@monthly 0 0 1 * *
@yearly 0 0 1 1 *
@annually 0 0 1 1 *
@midnight 0 0 * * *
=========== ============
To control the output of specials see `SPECIALS_CONVERSION` below.
How to Use the Module
=====================
Here is a simple example of how python-crontab is typically used. First the
CronTab class is used to instantiate a cron object, then the cron object is
used
to declaratively manipulate the cron (spawning a new job in this case).
Lastly,
declared changes get written to the crontab by calling write on the
object::
from crontab import CronTab
cron = CronTab(user='root')
job = cron.new(command='echo hello_world')
job.minute.every(1)
cron.write()
Alternatively, you can use the with context manager which will
automatically
call write on the cron object upon exit::
with CronTab(user='root') as cron:
job = cron.new(command='echo hello_world')
job.minute.every(1)
print('cron.write() was just executed')
**Note:** Several users have reported their new crontabs not saving
automatically or that the module doesn't do anything. You **MUST** use
write() if you want your edits to be saved out. See below for full details
on the use of the write function.
Getting access to a crontab can happen in five ways, three system methods
|