Skip to content

Commit

Permalink
Merge pull request #52441 from mchugh19/cron_perjob
Browse files Browse the repository at this point in the history
cron return a single line
  • Loading branch information
garethgreenaway authored Apr 8, 2019
2 parents 0516d5b + c4e702f commit 5f5b30d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions salt/modules/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# Import python libs
import os
import random
import logging

# Import salt libs
import salt.utils.data
Expand All @@ -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'):
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5f5b30d

Please sign in to comment.