diff --git a/salt/modules/cron.py b/salt/modules/cron.py index c833c807a174..85bd3a19b5b9 100644 --- a/salt/modules/cron.py +++ b/salt/modules/cron.py @@ -12,6 +12,7 @@ # Import python libs import os import random +import logging # Import salt libs import salt.utils.data @@ -27,6 +28,8 @@ SALT_CRON_IDENTIFIER = 'SALT_CRON_IDENTIFIER' SALT_CRON_NO_IDENTIFIER = 'NO ID SET' +log = logging.getLogger(__name__) + def __virtual__(): if salt.utils.path.which('crontab'): @@ -405,6 +408,36 @@ def list_tab(user): ls = salt.utils.functools.alias_function(list_tab, 'ls') +def get_entry(user, identifier=None, cmd=None): + ''' + Return the specified entry from user's crontab. + identifier will be used if specified, otherwise will lookup cmd + Either identifier or cmd should be specified. + + user: + User's crontab to query + + identifier: + Search for line with identifier + + cmd: + Search for cron line with cmd + + CLI Example: + + .. code-block:: bash + + salt '*' cron.identifier_exists root identifier=task1 + ''' + cron_entries = list_tab(user).get('crons', False) + for cron_entry in cron_entries: + if identifier and cron_entry.get('identifier') == identifier: + return cron_entry + elif cmd and cron_entry.get('cmd') == cmd: + return cron_entry + return False + + def set_special(user, special, cmd,