Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cron return a single line #52441

Merged
merged 2 commits into from
Apr 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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