Skip to main content

Description

Crontab module for read and writing crontab files and accessing the system cron automatically and simply using a direct API.

Comparing the below chart to http://en.wikipedia.org/wiki/Cron#CRON_expression you will note that W, L, # and ? symbols are not supported.

Field Name

Mandatory

Allowed Values

Allowed Special Characters

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

* / , -

Supported special cases allow crontab lines to not use fields. These are the supported aliases:

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

How to Use the Module

Getting access to a crontab can happen in four ways:

from crontab import CronTab

system_cron = CronTab()
user_cron = CronTab('root')
file_cron = CronTab(tabfile='filename.tab')
mem_cron = CronTab(tab="""
  * * * * * command
""")

Creating a new job is as simple as:

job  = cron.new(command='/usr/bin/echo')

And setting the job’s time restrictions:

job.minute.during(5,50).every(5)
job.hour.every(4)

job.dow.on('SUN')
job.month.during('APR', 'NOV')

Creating a job with a comment:

job = cron.new(command='/foo/bar',comment='SomeID')

Disabled or Enable Job:

job.enable()
job.enable(False)
False == job.is_enabled()

Validity Check:

True == job.is_valid()

Use a special syntax:

job.every_reboot()

Find an existing job by command:

list = cron.find_command('bar')

Find an existing job by comment:

list = cron.find_comment('ID or some text')

Set and get the comment for a job:

comment = job.meta(['New Comment for job'])

Clean a job of all rules:

job.clear()

Iterate through all jobs:

for job in cron:
    print job

Iterate through all lines:

for line in cron.lines:
    print line

Remove Items:

cron.remove( job )
cron.remove_all('echo')

Write CronTab back to system or filename:

cron.write()

Write CronTab to new filename:

cron.write( 'output.tab' )

Extra Support

  • Support for SunOS with compatability mode

  • Python 3.2 and Python 2.7 tested

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-crontab-1.3.2.tar.gz (21.1 kB view details)

Uploaded Source

File details

Details for the file python-crontab-1.3.2.tar.gz.

File metadata

File hashes

Hashes for python-crontab-1.3.2.tar.gz
Algorithm Hash digest
SHA256 79b06b31e758e574ef4b29c75ded169c5ccb410ac57c35aebcc56abf962c3c3b
MD5 27c5d9188efd43bc27349ccdccbb4244
BLAKE2b-256 881c898a13b24e9ddb6baf2156ed00f96683f7857a97c4cb5b20cba9d07aafbe

See more details on using hashes here.

Release history Release notifications | RSS feed

3.4.0

2 files

3.3.0

2 files

3.2.0

2 files

3.1.0

1 file

3.0.0

2 files

2.7.1

2 files

2.6.0

2 files

2.5.1

1 file

2.5.0

1 file

2.4.2

1 file

2.4.1

1 file

2.4.0

1 file

2.3.9

1 file

2.3.8

1 file

2.3.7

1 file

2.3.6

1 file

2.3.5

1 file

2.3.4

1 file

2.3.3

1 file

2.3.2

1 file

2.3.0

1 file

2.2.8

1 file

2.2.7

1 file

2.2.6

1 file

2.2.5

1 file

2.2.4

1 file

2.2.3

1 file

2.2.2

1 file

2.2.1

1 file

2.2.0

1 file

2.1.2

1 file

2.1.1

1 file

2.0.2

1 file

2.0.1

1 file

2.0

1 file

1.9.5

1 file

1.9.3

1 file

1.9.2

1 file

1.9.1

1 file

1.9.0

1 file

1.8.3

1 file

1.8.2

1 file

1.8.1

1 file

1.8

1 file

1.7.3

1 file

1.7.2

1 file

1.7.1

1 file

1.7.0

1 file

1.6.0

1 file

1.5.1

1 file

1.5

1 file

1.4.4

1 file

1.4.3

1 file

1.4.1

1 file

1.4

1 file

This release

1.3.2 This release

1 file

1.3

1 file

1.2

1 file

1.1

1 file

1.0.0

1 file

0.9.7

1 file

0.9.6

1 file

0.9.5

1 file

0.9.4

1 file

0.9.2

1 file

0.9

0.7

2 files

0.6

0.5

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page