Python Crontab 1.4 Released

Today I’ve put the finishing touches on python-crontab 1.4. This release updates the tests and fixes a couple of bugs as well as two really interesting features.

The first is the ability to pull a log from a crontab or cronjob. When creating a crontab in the usual way you can specify a optional log file, if not specified the value ‘/var/log/syslog’ is substituted. The log attribute then provides you a filtered log view which limits the lines returned by the iterator to those attributed to the user your crontab controls. This is of course by default the ‘root’ user, but can be other users too.

Conversely each job in the crontab can return a log iterator which limits the retuned entries to those for this job only. This allows the programmer to tell when cron jobs were last run.

The second large feature is the scheduler. Using the croniter python module, this feature returns date/times when cron jobs would run from any given datetime offset. This allows the programmer to compile a list of datetimes when the job would run in the future and in the past. Use the schedule attribute from the cron job object.

You can download the new release here: python-crontab-1.4 on PyPi

Python Crontab 1.0

Mission Accomplished! As a programmer, if you want to write crontabs, system and user tabs and want to access them in a less hairy way; then this is the module for you!

This 1.0 release includes lots of new unit tests, fixes for SunOS and other things and clean up of examples. You can get your source code from PyPi here: Awesome Source Code Link

And here’s a taste of a script using python-crontab:


from crontab import CronTab

system_cron = CronTab()
user_cron = CronTab(user='username')
fake_cron = CronTab(fake_tab='')

Creating a new job:

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

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

New job for reboot:

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

Finding jobs with certain commands:

list = cron.find_command('bar')

Iterating over all cronjobs:

for job5 in cron:
print job5

Launchpad project page, GPLv3