logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

systemd.cron — systemd units for cron periodic jobs

Bugs

       Do not use with a cron daemon or anacron, otherwise scripts may be executed multiple times.

       All  services  are  run  with  Type=oneshot,  which means you can't use systemd-cron to launch long lived
       forking daemons.

Description

       These  units  provide  the  functionality  usually  afforded  by  the  cron  daemon  — running scripts in
       /etc/cron.schedule directories and sending mail on failure.

       Crontabs    are    monitored    by    cron-update.path    and    are    automatically    translated    by
       systemd-crontab-generator(8).

Diagnostics

systemctllist-timers shows an overview of current timers and when they'll elapse.

Examples

Startcronunits#systemctlstartcron.targetStartcronunitsonboot#systemctlenablecron.targetViewscriptoutput#journalctl-ucron-dailyOverridesomegeneratedtimerstarttime#systemctleditcron-geoip-database-contrib-root-1.timer
       and add
           [Timer]
           OnCalendar=
           OnCalendar=*-*-* 18:36:00

   Overridecron-daily.servicepriority,usefulforoldcomputers#systemctleditcron-daily.service
       and add
           [Service]
           CPUSchedulingPolicy=idle
           IOSchedulingClass=idle

   Exampleservicefileexecutedeveryhour
       [Unit]
       Description=Update the man db

       [Service]
       Nice=19
       IOSchedulingClass=2
       IOSchedulingPriority=7
       ExecStart=/usr/bin/mandb --quiet

       [Install]
       WantedBy=cron-hourly.target

Extensions

       The generator can optionally turn any crontabs in persistent timers with the PERSISTENT=true flag,  while
       a regular cron and anacron setup won't catch up on the missed executions of crontabs on reboot.

Files

/etc/crontab              Administrator's system crontab, see crontab(5).
       /etc/cron.d               System crontabs managed by packages live here.
       /etc/anacrontabanacrontab(5)
       /var/spool/cron/crontabs  Users' crontabs live here.

       /etc/cron.hourly          Directory for scripts to be executed every hour.
       /etc/cron.daily           Directory for scripts to be executed every day.
       /etc/cron.weekly          Directory for scripts to be executed every week.
       /etc/cron.monthly         Directory for scripts to be executed every month.
       /etc/cron.yearly          Directory for scripts to be executed every year.

       /usr/lib/systemd/system/schedule.timer/etc/systemd/system/schedule.timer
                                 Native systemd timers will override cron jobs with the same name.

                                 You  can  also  use  this  mechanism  to mask an unneeded crontab provided by a
                                 package via systemctlmaskpackage.timer.

Name

       systemd.cron — systemd units for cron periodic jobs

Notes

       The  exact  times scripts are executed is determined by the values of the special calendar events hourly,
       daily, weekly, monthly, and yearly defined in systemd.time(7).

See Also

crontab(1),    systemd(1),    crontab(5),    systemd.service(5),    systemd.timer(5),    systemd.unit(5),
       systemd.time(7), run-parts(8), systemd-crontab-generator(8)

systemd-cron 2.5.1-2                               2023-08-13                                    SYSTEMD.CRON(7)

Synopsis

       cron.target
       cron-update.path, cron-update.service
       cron-mail@.service

Units

cron.target              Target unit which starts the others, needs to be enabled to use systemd-cron.
       cron-update.path         Monitors “FILES” and calls
       cron-update.service      which runs systemctldaemon-reload to re-run the generator.

       cron-mail@.service       Sends mail (via sendmail(1), which can be overridden with $SENDMAIL) in  case  a
                                cron  service  unit fails, succeeds, or succeeds-but-only-if-it-wrote-something.
                                The instance name (the bit after the @) is the unit name, followed  by  optional
                                arguments delimited by colons (‘:’):
                                nonempty    exit  silently  if  the  unit  produced  no  output  (equivalent  to
                                            CRON_MAIL_SUCCESS=nonempty) for OnSuccess=),
                                nometadata  don't include systemctlstatus output, don't  add  usual  journalctl
                                            metadata  to the output (equivalent to CRON_MAIL_FORMAT=nometadata),
                                            and
                                verbose     log reason before exiting silently.
                                (upper-case arguments are ignored).

                                Overriding this via systemctledit can be useful,  especially  for  units  under
                                /etc/cron.*.

See Also