Module: CronEdit

Defined in:
lib/cronedit.rb

Overview

:title:CronEdit - Ruby editior library for cron and crontab - RDoc documentation

CronEdit - Ruby editor library for crontab.

Allows to manipulate crontab from comfortably from ruby code. You can add/modify/remove (aka CRUD) named crontab entries individually with no effect on the rest of your crontab. You can define cron entry definitions as standard text definitions '10 * * * * echo 42' or using Hash notation {:minute=>10, :command=>'echo 42'} (see CronEntry ::DEFAULTS) Additionally you can parse cron text definitions to Hash.

From other features: CronEdit allows you to make bulk updates of crontab; the same way you manipulate live crontab you can edit file or in-memory definitions and combine them arbitrarily.

Install

Usage

Class methods offer quick crontab operations. Three examples:

CronEdit::Crontab.Add  'agent1', '5,35 0-23/2 * * * echo agent1'
CronEdit::Crontab.Add  'agent2', {:minute=>5, :command=>'echo 42'}
CronEdit::Crontab.Remove 'someId'

Define a batch update and list the current content:

cm = CronEdit::Crontab.new 'user'
cm.add 'agent1', '5,35 0-23/2 * * * echo agent1'
...
cm.add 'agent2', {:minute=>5, :command=>'echo 42'}
cm.commit
p cm.list

see CronEdit::Crontab class for all available methods

You can do a bulk merge (or removal) of definitions from a file using CronEdit::FileCrontab

fc = FileCrontab.new 'example1.cron'
Crontab.Merge fc
p Crontab.List
Crontab.Subtract fc

Similary to CronEdit::FileCrontab you can you also CronEdit::DummyCrontab for in-memory crontabs. Above all, you can combine all three crontab implementations Crontab, FileCrontab, DummyCrontab arbitrarily.

see test/examples/examples.rb for more examples !

Author

Viktor Zigo, alephzarro.com, All rights reserved. You can redistribute it and/or modify it under the same terms as Ruby. (parts of the cronentry definition parsing code originally by [email protected])

Sponsored by: 7inf.com

History

  • version: 0.3.0 2008-02-02

** keeps/survives full fromatting; FileCrontab; DummyCrontab; bulk addition and removal; clear crontab; more testcases; examples; and other

  • version: 0.2.0

TODO

  • add Utils: getNext execution

  • platform specific options (headers; vixiecron vs. dilloncron)

Defined Under Namespace

Classes: CronEntry, Crontab, DummyCrontab, EntryPlaceholder, FileCrontab