Cron

From Alpine Linux
Revision as of 09:47, 12 November 2024 by Prabuanand (talk | contribs) (new page created to document steps needed to make anacron work in alpine linux)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This page documents the working of Cron, a job scheduler on Unix-like operating systems. Cron is most suitable for scheduling repetitive tasks. Scheduling one-time tasks can be accomplished using the associated at utility. There are many cron implementations, but Alpine Linux comes inbuilt with the BusyBox version of cron. Some of the other packages available in Alpine Linux are cronie, fcron, dcron.

Cronie

The default cron is ideal for systems that run 24x7. For desktops, due to irregular nature of turning OFF and ON, it is easy to miss the jobs scheduled through regular cron. The cronie package comes with anacron tool, which does this kind of asynchronous job processing.

Anacron

Here are the steps to use anacron in Alpine Linux:

  1. Add the line @reboot /usr/sbin/anacron -s to the crontab of the root user:

    # crontab -e

  2. Once edited, crontab should appear appears as follows:

    Contents of /var/spool/cron/crontabs/root

    # do daily/weekly/monthly maintenance # min hour day month weekday command */15 * * * * run-parts /etc/periodic/15min 0 * * * * run-parts /etc/periodic/hourly 0 2 * * * run-parts /etc/periodic/daily 0 3 * * 6 run-parts /etc/periodic/weekly 0 5 1 * * run-parts /etc/periodic/monthly @reboot /usr/sbin/anacron -s
  3. Anacron needs the folder /var/spool/anacron to avoid the error cron.err anacron[2893]: Can't chdir to /var/spool/anacron: No such file or directory. So create the folder using the command:

    # mkdir /var/spool/anacron

  4. Edit the configuration file /etc/anacrontab and test the configuration validity by anacron -T.
  5. Reboot the computer to test the working of anacron. The syslog file /var/log/messages captures messages from anacron and can be searched by cat /var/log/messages |grep anacron.

See Also