Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert cronjob file to SaltStack state
import re
cronjob_content = """ PAST YOUR CRONJOB HERE """
cronjob_regex = re.compile(r'^([^#]\S*?) (\S+) (\S+) (\S+) (\S+)\s+(.+)$')
for n, (minute, hour, daymonth, month, dayweek, exp) in enumerate([i.groups() for i in map(cronjob_regex.search, d.splitlines()) if i], 1):
print "cronjob-%02d:" % n
print " cronjob.present:"
for k, v in {"minute": minute, "hour": hour, "daymonth": daymonth, "month": month, "dayweek": dayweek}.items():
if v != "*":
print " - %s: %s" % (k, v)
print " - name: %s" % exp
print
cronjob-01:
cronjob.present:
- minute: */5
- name: date
cronjob-02:
cronjob.present:
- hour: 0
- minute: 02
- name: bash -c "[[ -f /tmp/exist_file ]]"
cronjob-03:
cronjob.present:
- minute: */5
- name: echo saltstack &>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.