Skip to main content
Manage crontab entries.

Functions

crontab.crontab

Add/remove/update crontab entries.
crontab.crontab(
    command,
    present=True,
    user=None,
    cron_name=None,
    minute="*",
    hour="*",
    month="*",
    day_of_week="*",
    day_of_month="*",
    special_time=None,
    interpolate_variables=False,
)
Cron commands: Unless cron_name is specified the command is used to identify crontab entries. This means commands must be unique within a given users crontab. If you require multiple identical commands, provide a different name argument for each.Special times: When provided, special_time will be used instead of any values passed in for minute/hour/month/day_of_week/day_of_month.

Examples

from pyinfra.operations import crontab

# Backup /etc weekly
crontab.crontab(
    name="Backup /etc weekly",
    command="/bin/tar cf /tmp/etc_bup.tar /etc",
    cron_name="backup_etc",
    day_of_week=0,
    hour=1,
    minute=0,
)

# Run a script daily at midnight
crontab.crontab(
    name="Run daily cleanup",
    command="/usr/local/bin/cleanup.sh",
    special_time="@daily",
)

Build docs developers (and LLMs) love