<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hazardchem</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hazardchem"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Hazardchem"/>
	<updated>2026-04-28T10:45:41Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Cron&amp;diff=32274</id>
		<title>Cron</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Cron&amp;diff=32274"/>
		<updated>2026-04-09T03:13:53Z</updated>

		<summary type="html">&lt;p&gt;Hazardchem: /* Configuration */ Add notes about busybox-suid&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page documents the working of [https://en.wikipedia.org/wiki/Cron 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. &lt;br /&gt;
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 {{Pkg|cronie}}, {{Pkg|fcron}} and {{Pkg|dcron}}.&lt;br /&gt;
&lt;br /&gt;
== Basic example == &lt;br /&gt;
&lt;br /&gt;
The below example uses a cron job to keep the time in sync. This example works with all versions of cron including the [[BusyBox]] version of cron. Add the following file or a symlink to {{Path|/etc/periodic/daily}} folder or use another folder under the {{Path|/etc/periodic/}} hierarchy if you want to run the script more/less frequently.&lt;br /&gt;
&lt;br /&gt;
Create a script file {{Path|/etc/periodic/daily/do-ntp}} as follows:{{Cat|/etc/periodic/daily/do-ntp|&amp;lt;nowiki&amp;gt;#!/bin/sh&lt;br /&gt;
ntpd -d -q -n -p uk.pool.ntp.org&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
Make the script file executable:{{Cmd|# chmod +x /etc/periodic/daily/do-ntp}}&lt;br /&gt;
&lt;br /&gt;
This script queries the uk time server pool - modify this to suit your location, or just use pool.ntp.org. Refer for [https://www.pool.ntp.org/zone/@ more info].&lt;br /&gt;
&lt;br /&gt;
To check whether any {{ic|cron}} service is running, verify the output for the command : {{cmd|&amp;lt;nowiki&amp;gt;# rc-update |grep cron&lt;br /&gt;
crond |      default &amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
== Busybox crond ==&lt;br /&gt;
&lt;br /&gt;
{{ic|crond}} is the builtin cron implementation from [[BusyBox]]. Since Busybox follows only [https://pubs.opengroup.org/onlinepubs/9799919799/utilities/crontab.html POSIX] standard, only &amp;quot;0&amp;quot; is supported for Sunday. It does not understand &amp;quot;7&amp;quot; as a valid day of the week.  &lt;br /&gt;
&lt;br /&gt;
=== Configuration ===&lt;br /&gt;
&lt;br /&gt;
The {{ic|crond}} service from [[BusyBox]] is managed by [[OpenRC]].&lt;br /&gt;
&lt;br /&gt;
To immediately start, stop and restart the {{ic|crond}} service: {{cmd|# rc-service crond start}}&lt;br /&gt;
&lt;br /&gt;
To add {{ic|crond}} service to the boot sequence: {{cmd|# rc-update add crond}}&lt;br /&gt;
&lt;br /&gt;
{{Note|Whenever an alternative cron implementation is used, ensure that the {{ic|crond}} service is stopped and removed from [[OpenRC]] as follows:{{Cmd|&amp;lt;nowiki&amp;gt;# rc-service crond stop&lt;br /&gt;
# rc-update del crond &amp;lt;/nowiki&amp;gt;}} }}&lt;br /&gt;
&lt;br /&gt;
{{Note|If editing crotab and getting suid issues, ensure that {{ic|busybox-suid}} is installed and might need updating with:{{Cmd|&amp;lt;nowiki&amp;gt;# apk add --update busybox-suid &amp;lt;/nowiki&amp;gt;}} }}&lt;br /&gt;
&lt;br /&gt;
== Asynchronous job processing ==&lt;br /&gt;
&lt;br /&gt;
For systems that do not run continuously, like laptops or regular desktop computers, cron jobs with large time intervals between invocations may not be executed at all if the system is suspended or powered off during the cron job&#039;s scheduled time. To work around this, [[#Cronie|Cronie]] provides {{ic|anacron}}. However, in [[#dcron|dcron]] special directives like &amp;lt;code&amp;gt;@daily&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;@monthly&amp;lt;/code&amp;gt; keep track of the last execution time and still execute if the system was down while the job was supposed to run. &lt;br /&gt;
&lt;br /&gt;
== Cronie ==&lt;br /&gt;
&lt;br /&gt;
The {{Pkg|cronie}} package comes with &amp;lt;code&amp;gt;anacron&amp;lt;/Code&amp;gt; tool for [[#Asynchronous job processing|asynchronous job processing]]. To use it, first install the {{Pkg|cronie}} package: {{Cmd|# apk add {{Pkg|cronie}}}}&lt;br /&gt;
&lt;br /&gt;
Finally, start {{Pkg|cronie}} and tell [[OpenRC]] to start it at boot:{{Cmd|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 # rc-service cronie start&lt;br /&gt;
 # rc-update add cronie&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Configuration ===&lt;br /&gt;
&lt;br /&gt;
Here are the steps to use &amp;lt;code&amp;gt;anacron&amp;lt;/Code&amp;gt; tool from cronie in Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
# Add the line {{Codeline|&amp;lt;code&amp;gt;@reboot /usr/sbin/anacron -s&amp;lt;/code&amp;gt;}} to the crontab of the &#039;&#039;&#039;root&#039;&#039;&#039; user:&lt;br /&gt;
#: {{Cmd|# crontab -e}}&lt;br /&gt;
# Once edited, &#039;&#039;&#039;root&#039;&#039;&#039; crontab should appear as follows, when viewed using the command {{Codeline|&amp;lt;code&amp;gt;# crontab -l &amp;lt;/code&amp;gt;}} or viewed directly:&lt;br /&gt;
#:{{cat|/var/spool/cron/crontabs/root| &lt;br /&gt;
# do daily/weekly/monthly maintenance&lt;br /&gt;
# min	hour	day	month	weekday	command&lt;br /&gt;
*/15	*	*	*	*	run-parts /etc/periodic/15min&lt;br /&gt;
0	*	*	*	*	run-parts /etc/periodic/hourly&lt;br /&gt;
0	2	*	*	*	run-parts /etc/periodic/daily&lt;br /&gt;
0	3	*	*	6	run-parts /etc/periodic/weekly&lt;br /&gt;
0	5	1	*	*	run-parts /etc/periodic/monthly&lt;br /&gt;
@reboot /usr/sbin/anacron -s&lt;br /&gt;
}}&lt;br /&gt;
# Anacron needs the folder {{Path|/var/spool/anacron}} to avoid the error {{Codeline|cron.err anacron[2893]: Can&#039;t chdir to /var/spool/anacron: No such file or directory}}. So create the folder using the command:&lt;br /&gt;
#: {{Cmd|# mkdir /var/spool/anacron}}&lt;br /&gt;
# Edit the configuration file {{Path|/etc/anacrontab}} where jobs are listed as per the above crontab syntax, and test the configuration validity by &amp;lt;Code&amp;gt;anacron -T&amp;lt;/Code&amp;gt;.&lt;br /&gt;
# Reboot the computer to test the working of anacron. The syslog file {{Path|/var/log/messages}} captures messages from anacron and can be searched by &amp;lt;Code&amp;gt;cat /var/log/messages |grep anacron&amp;lt;/Code&amp;gt;.&lt;br /&gt;
For more information about {{Pkg|cronie}}&#039;s options and its &amp;lt;code&amp;gt;anacrontab&amp;lt;/code&amp;gt; format, check out the &amp;lt;code&amp;gt;anacrontab(5)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;anacron(8)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;crond(8)&amp;lt;/code&amp;gt; manpages, which you can install with the {{Pkg|cronie-doc}} package.&lt;br /&gt;
&lt;br /&gt;
== dcron ==&lt;br /&gt;
&lt;br /&gt;
Another available crond that fully integrates the features of &amp;lt;code&amp;gt;anacron&amp;lt;/code&amp;gt; is {{Pkg|dcron}}, &amp;quot;dillon&#039;s lightweight cron daemon&amp;quot;. To use it, first install the {{Pkg|dcron}} package:{{Cmd|# apk add dcron}}&lt;br /&gt;
&lt;br /&gt;
Finally, start {{Pkg|dcron}} and tell [[OpenRC]] to start it at boot:{{Cmd|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 # rc-service dcron start&lt;br /&gt;
 # rc-update add dcron&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Configuration ===&lt;br /&gt;
&lt;br /&gt;
You can add directives to the crontab with the &amp;lt;code&amp;gt;crontab -e&amp;lt;/code&amp;gt; command, also including the &amp;lt;code&amp;gt;@hourly&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;@daily&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;@weekly&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;@monthly&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;@yearly&amp;lt;/code&amp;gt; directives.&lt;br /&gt;
&lt;br /&gt;
The syntax of these special directives slightly differs from &amp;lt;code&amp;gt;anacron&amp;lt;/code&amp;gt;. Here is how Alpine&#039;s default could be adjusted to use the {{Pkg|dcron}} syntax with the special directives to ensure that they are executed even with systems that are not always running:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/var/spool/cron/crontabs/root|&amp;lt;nowiki&amp;gt;# do daily/weekly/monthly maintenance&lt;br /&gt;
# min   hour    day     month   weekday command&lt;br /&gt;
*/15    *       *       *       *       run-parts /etc/periodic/15min&lt;br /&gt;
@hourly         ID=periodic.hourly      run-parts /etc/periodic/hourly&lt;br /&gt;
@daily          ID=periodic.daily       run-parts /etc/periodic/daily&lt;br /&gt;
@weekly         ID=periodic.weekly      run-parts /etc/periodic/weekly&lt;br /&gt;
@monthly        ID=periodic.monthly     run-parts /etc/periodic/monthly&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
As you can see, the name or &amp;quot;ID&amp;quot; of a job is set in the style of a shell variable assignment. For more information about {{Pkg|dcron}}&#039;s options and its &amp;lt;code&amp;gt;crontab&amp;lt;/code&amp;gt; format, check out the &amp;lt;code&amp;gt;crontab(1)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;crond(8)&amp;lt;/code&amp;gt; manpages, which you can install with the {{Pkg|dcron-doc}} package.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/cronie-crond/cronie Official cronie website]&lt;br /&gt;
* [https://www.jimpryor.net/linux/dcron.html Official dcron website]&lt;br /&gt;
* [https://crontab.guru/ crontab Generator]&lt;br /&gt;
* [https://wiki.archlinux.org/title/Cron Archwiki Cron page]&lt;br /&gt;
&lt;br /&gt;
[[Category:System Administration‏‎ ]]&lt;/div&gt;</summary>
		<author><name>Hazardchem</name></author>
	</entry>
</feed>