Blocks that run commands, now or on a schedule.

Cron Job

Adds a line to a user’s crontab, and reloads cron when it changes.

Generates: a methods promise.

Settings

Setting Required Description
Command Yes Start with an absolute path. Runs with cron’s environment, not the agent’s. The job runs every day of the month and week, at the hours and minutes set below; Windows hosts skip it.
Run as Yes Default: root.
Hours Yes Cron hour field: * for every hour, 3 or 0,12 or */6. Default: *.
Minutes Yes Cron minute field: 0, 15,45 or */10. Default: 0.

Example

The policy it generates, for example:

# Back up nightly
methods:
  "cron job for root"
    usebundle => default:cronjob(
      "/usr/local/bin/backup.sh", "root", "3", "30"
    );

Run Command

Runs a command via the shell.

Generates: a commands promise.

Settings

Setting Required Description
Command Yes Start with an absolute path (/usr/bin/…). $(name) is a CFEngine variable, so write a shell $( ) as $(const.dollar)( ).
How often No A command runs every time the agent does (every 5 minutes by default) unless limited here. One of: Every agent run, At most once an hour, At most once a day, At most once a week, or Other… and Minutes between runs, at least 1. Default: At most once a day.

Example

The policy it generates, for example:

# Update CA certificates
commands:
  "/usr/sbin/update-ca-certificates"
    contain => default:in_shell,
    action => default:if_elapsed("1440");