Crontab listings

CrontabL base class

class insights.parsers.crontab.CrontabL(context, extra_bad_lines=None)[source]

Bases: CommandParser

Parses output of crontab -l command.

Each row of the crontab is converted into a dictionary with keys for each field. For example one row would look like:

  'minute': '*',
  'hour': '*',
  'day_of_month': '*',
  'month': '*',
  'day_of_week': '*',
  'command': '/usr/bin/keystone-manage token_flush > /dev/null 2>&1'

Crontab parses the line in the same way that cron(1) does. Lines that are blank or start with a comment are ignored. Environment lines of the form ‘KEY = value’ (with optional spacing around the equals sign) are stored in the ‘environment’ dictionary attribute by key. Lines containing a valid crontab line, with five recogniseable time fields and a command, are stored in the data property and accessed through the pseudo-list interface and search method. All other lines are stored in the invalid_lines property.

Crontab recognises the extension of time signature ‘nicknames’, which take place of the first five parts of a standard crontab line:

  • @reboot : Run once after reboot.

  • @yearly : Run once a year, ie. “0 0 1 1 *”.

  • @annually : Run once a year, ie. “0 0 1 1 *”.

  • @monthly : Run once a month, ie. “0 0 1 * *”.

  • @weekly : Run once a week, ie. “0 0 * * 0”.

  • @daily : Run once a day, ie. “0 0 * * *”.

  • @hourly : Run once an hour, ie. “0 * * * *”.

The Crontab class recognises these nicknames. In the case of the @reboot’ nickname, the row will not contain the ‘minute’, ‘hour’, ‘day_of_month’, ‘month’, or ‘day_of_week’ keys, and instead will contain the key ‘time’ with the value @reboot’ (as well as the usual ‘command’ key). All other keywords are translated directly into their five-part equivalent and parsed as a normal crontab line.

Lines that can’t be parsed because they don’t contain at least six words or meet the criteria for environment line or time signature nicknames are stored in the invalid_lines property.

Sample input looks like:

# send mail to admin address.
* * * * * /usr/bin/keystone-manage token_flush > /dev/null 2>&1
33 0 * * * /bin/heat-manage purge_deleted -g days 7


>>> crontab = shared[KeystoneCrontab]
[{'minute': '*', 'hour': '*', 'day_of_month': '*', 'month': '*', 'day_of_week': '*',
  'command': '/usr/bin/keystone-manage token_flush > /dev/null 2>&1'}]
>>> [r['minute'] for r in crontab]
['*', '33']
>>> crontab.invalid_lines
>>> len(crontab)  # Number of actual entries
>>> crontab[0]  # Individual entry access
{'minute': '*', 'hour': '*', 'day_of_month': '*', 'month': '*', 'day_of_week': '*',
  'command': '/usr/bin/keystone-manage token_flush > /dev/null 2>&1'}
>>> 'MAILTO' in crontab.environment  # Dictionary of environment settings
>>> crontab.environment['MAILTO']

List of parsed lines. These can be accessed directly through the object as seen in the examples.




A dictionary of environment declarations in the crontab.




Lines that could not be parsed as normal crontab entries.




This method must be implemented by classes based on this class.


list: Returns list of dicts for lines that have filter_str in the command.

HeatCrontab - command crontab -l -u heat

class insights.parsers.crontab.HeatCrontab(context, extra_bad_lines=None)[source]

Bases: CrontabL

Parses output of the crontab -l -u heat command.

KeystoneCrontab - command crontab -l -u keystone

class insights.parsers.crontab.KeystoneCrontab(context, extra_bad_lines=None)[source]

Bases: CrontabL

Parses output of the crontab -l -u keystone command.

RootCrontab - command crontab -l -u root

class insights.parsers.crontab.RootCrontab(context, extra_bad_lines=None)[source]

Bases: CrontabL

Parses output of the crontab -l -u root command.