zester
GuidesModules

cron

The cron.* family of state modules.

ModuleSummary
cron.absentEnsure a crontab entry does not exist for a user.
cron.presentEnsure a crontab entry exists for a user with the given schedule and command.

All states also accept the full set of requisite parameters and Salt-parity state attributes — see Dependencies & Requisites.


Family Parameters

These parameters are declared once by the family's shared parameter components — every member that exposes one accepts the identical contract.

ParameterTypeRequiredDefaultDescription
userstringNorootuser whose crontab is managed; defaults to root
commandstringYes(none)command line of the managed crontab entry; required

cron.absent

Ensure a crontab entry does not exist for a user.

Source: pkg/state/modules/cron/cron_absent.go


cron.absent ensures no crontab entry with the given command exists in the target user's crontab. command is required and identifies the line to remove; user defaults to root. The name parameter is a label for the state only (defaulting to the state ID) — removal matches on the command, not the label.


Parameters

ParameterTypeRequiredDefaultDescription
namestringNoState IDlabel for the state; defaults to the state ID

cron.absent also accepts the family parameters user, command — see Family Parameters.


Effects

Check

Lists the user's crontab and reports a change when any entry's command matches the declared command; otherwise it reports no change.

Apply

Removes the crontab entry matching the command through the cron provider. Reports the user and command in its details.

Revert

Cannot restore a deleted crontab entry (the removed line's schedule is not recorded), so Revert is an explicit no-op rather than a guessed re-creation.


Examples

Remove a legacy backup job

The entry is identified by its command.

remove-legacy-backup:
  cron.absent:
    - user: root
    - command: /usr/local/bin/old_backup.sh

Remove a cron entry ad hoc

The bare positional argument is the state's name; command is a key=value.

zester '*' cron.absent old-job command=/usr/local/bin/old_backup.sh

See Also


cron.present

Ensure a crontab entry exists for a user with the given schedule and command.

Source: pkg/state/modules/cron/cron_present.go


cron.present ensures a single crontab entry exists in the target user's crontab. The entry's IDENTITY is the state's name (defaulting to the state ID), stamped as a # ZESTER_CRON_ID: marker comment on the line — so editing the command under an unchanged name REPLACES the old line in place instead of orphaning it, and two states with distinct names but the same command coexist. command is required; user defaults to root and each of the five schedule fields (minute, hour, daymonth, month, dayweek) defaults to *.


Parameters

ParameterTypeRequiredDefaultDescription
namestringNoState IDidentifier comment stamped on the crontab line (its Salt-identifier identity); defaults to the state ID
minutestringNo*minute field (0-59 or *); defaults to *
hourstringNo*hour field (0-23 or *); defaults to *
daymonthstringNo*day-of-month field (1-31 or *); defaults to *
monthstringNo*month field (1-12 or *); defaults to *
dayweekstringNo*day-of-week field (0-7 or *); defaults to *

cron.present also accepts the family parameters user, command — see Family Parameters.


Effects

Check

Lists the user's crontab and locates the entry sharing this state's identity — the marker comment when present, or, as an adoption fallback, an exact command match among label-less (hand-written) lines. Reports a change when no such entry exists, or when the located entry's command (compared with internal whitespace collapsed, matching the crontab parser), schedule fields, or identifier comment drift from the declared values.

Apply

Re-lists the crontab (a self-contained flow: a watch-forced Apply bypasses Check). An already-converged entry is a clean no-op — no crontab rewrite, no lying change. Otherwise it writes the desired entry, stamping the identifier comment (adopting a matching label-less line rather than duplicating it), and memoizes the replaced or adopted original for revert. Reports the user, command, and schedule in its details.

Revert

Undoes only what this run's Apply wrote. An entry created under the same identity as a prior one is restored in place; an adopted label-less line is put back; a freshly created entry is removed by its (command-scoped) line, preserving other names' same-command entries which are re-added. A fresh instance (a standalone revert) recorded nothing and is an explicit no-op — it never deletes an entry by bare command.


Examples

Nightly database backup

command is required; the schedule fields default to * where omitted.

backup-db:
  cron.present:
    - user: postgres
    - command: /usr/local/bin/pg_backup.sh
    - minute: "0"
    - hour: "3"
    - require:
      - "pkg.installed:postgresql"

Run a command every five minutes

A numeric minute is coerced to its string form (minute 5, not every minute — see the BD-3 divergence).

poll:
  cron.present:
    - command: /usr/local/bin/poll.sh
    - minute: 5

Create a cron entry ad hoc

The bare positional argument is the entry's name (its identifier comment); command is a key=value.

zester 'web*' cron.present nightly command=/usr/local/bin/nightly.sh hour=2 minute=0

See Also

On this page