Cron: Difference between revisions
Prabuanand (talk | contribs) (new page created to document steps needed to make anacron work in alpine linux) |
Prabuanand (talk | contribs) m (added command needed to view) |
||
Line 12: | Line 12: | ||
# Add the line {{Codeline|<code>@reboot /usr/sbin/anacron -s</code>}} to the crontab of the '''root''' user: | # Add the line {{Codeline|<code>@reboot /usr/sbin/anacron -s</code>}} to the crontab of the '''root''' user: | ||
#: {{Cmd|# crontab -e}} | #: {{Cmd|# crontab -e}} | ||
# Once edited, crontab should appear | # Once edited, '''root''' crontab should appear as follows, when viewed using the command {{Codeline|<code># crontab -l </code>}} or viewed directly: | ||
#:{{cat|/var/spool/cron/crontabs/root| | #:{{cat|/var/spool/cron/crontabs/root| | ||
# do daily/weekly/monthly maintenance | # do daily/weekly/monthly maintenance |
Latest revision as of 09:51, 12 November 2024
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:
- Add the line
@reboot /usr/sbin/anacron -s
to the crontab of the root user:# crontab -e
- Once edited, root crontab should appear as follows, when viewed using the command
# crontab -l
or viewed directly: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
- 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
- Edit the configuration file /etc/anacrontab and test the configuration validity by
anacron -T
. - 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
.