Repository navigation
Expand file tree
/
Copy pathcron.html
More file actions
73 lines (73 loc) · 8.39 KB
/
Copy pathcron.html
File metadata and controls
73 lines (73 loc) · 8.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Cron - UraniumOS</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header><div class="in"><nav class="l"><a href="index.html">Home</a><a href="download.html">Download</a><a href="docs.html" aria-current="page">Documentation</a><a href="rod.html">Packages</a><a href="news.html">News</a><a href="about.html">About</a></nav><nav class="r"><a href="features.html">Features</a><a href="media.html">Install</a><a href="security.html">Security</a><a href="hardware.html">Hardware</a></nav></div></header>
<main class="in docs">
<aside><div class="sbhead"><a class="sbh" href="index.html">⌂ UraniumOS</a><svg aria-hidden="true" viewBox="-50 -50 100 100"><circle r="48" fill="#f2d21b"/><circle r="6.5" fill="#1b1b19"/><path fill="#1b1b19" d="M6.50 -11.26 A13 13 0 0 0 -6.50 -11.26 L-20.00 -34.64 A40 40 0 0 1 20.00 -34.64 Z M-13.00 -0.00 A13 13 0 0 0 -6.50 11.26 L-20.00 34.64 A40 40 0 0 1 -40.00 -0.00 Z M6.50 11.26 A13 13 0 0 0 13.00 0.00 L40.00 0.00 A40 40 0 0 1 20.00 34.64 Z"/></svg><span class="ver">0.1.1</span><input type="search" placeholder="Search docs" aria-label="Search docs"></div><h4>Read first</h4><ul><li><a href="differences.html">Differences and known failures</a></li></ul><h4>1 Installation</h4><ul><li><a href="download.html">1.1 Download</a></li><li><a href="media.html">1.2 Live medium</a></li><li><a href="partitioning.html">1.3 Partitioning notes</a></li><li><a href="manual-install.html">1.4 Manual install</a></li><li><a href="first-steps.html">1.5 First steps</a></li></ul><h4>2 Configuration</h4><ul><li><a href="users.html">2.1 Users and groups</a></li><li><a href="keyboard.html">2.2 Keyboard</a></li><li><a href="time.html">2.3 Date and time</a></li><li><a href="services.html">2.4 Services</a></li><li><a href="cron.html" aria-current="page">2.5 Cron</a></li><li><a href="network.html">2.6 Network</a></li><li><a href="ssh.html">2.7 SSH</a></li><li><a href="blastdoor.html">2.8 Firewall</a></li><li><a href="desktop.html">2.9 Desktop</a></li><li><a href="firmware.html">2.10 Firmware</a></li><li><a href="boot.html">2.11 Boot</a></li><li><a href="kernel.html">2.12 Kernel</a></li><li><a href="storage.html">2.13 Storage</a></li><li><a href="security.html">2.14 Security</a></li><li><a href="geiger.html">2.15 Health report</a></li></ul><h4>3 Packages</h4><ul><li><a href="rod.html">3.1 rod</a></li><li><a href="cheatsheet.html">3.2 rod cheat sheet</a></li><li><a href="not-in-rod.html">3.3 Package not in rod</a></li><li><a href="recipes.html">3.4 Recipes</a></li><li><a href="silo.html">3.5 Containers</a></li><li><a href="hazmat.html">3.6 Sandboxes</a></li></ul><h4>4 Snapshots</h4><ul><li><a href="scram.html">4.1 scram</a></li><li><a href="backups.html">4.2 Backups</a></li></ul><h4>5 Reference</h4><ul><li><a href="system.html">5.1 System and files</a></li><li><a href="troubleshooting.html">5.2 Troubleshooting</a></li><li><a href="hardware.html">5.3 Hardware status</a></li><li><a href="faq.html">5.4 FAQ</a></li></ul><h4>6 Project</h4><ul><li><a href="developers.html">6.1 Developers</a></li><li><a href="contributing.html">6.2 Contributing</a></li><li><a href="about.html">6.3 About</a></li><li><a href="features.html">6.4 Features</a></li><li><a href="news.html">6.5 News</a></li></ul></aside><article><div class="band"><h1>Cron</h1></div>
<p>Scheduled jobs are run by the <code>crond</code> service, which is busybox crond started as <code>crond -f -c /etc/crontabs</code>. It runs as root, reads one file per user from <code>/etc/crontabs</code> and starts each job as the owner of the file. Its output is written to <code>/var/log/crond/current</code>; see <a href="services.html">services</a>.</p>
<h2>File format</h2>
<p>The file is named after the user. A line has five time fields, which are the minute, the hour, the day of the month, the month and the day of the week, followed by the command. A line that begins with <code>#</code> is a comment. The command is run with <code>/bin/sh</code>, which is bash from the profile.</p>
<p>New and changed files are read without a restart, and a job runs at the next full minute. Only root may write to the directory, so a user file such as <code>/etc/crontabs/dave</code> must be written by root.</p>
<h2>The jobs of the system</h2>
<pre><code># cat /etc/crontabs/root
# minute hour day month weekday command
0 4 * * 0 fstrim -a
0 5 1 * * btrfs scrub start -B /</code></pre>
<p>The first job runs on Sundays at 04:00 and informs every mounted filesystem that supports it which blocks are free. Run by hand, it prints:</p>
<pre><code># fstrim -a -v
/boot: 225 MiB (235945472 bytes) trimmed on /dev/vda1
/run/scram/top: 10.5 GiB (11252236288 bytes) trimmed on /dev/vda2</code></pre>
<p>The second job runs on the first of each month at 05:00. <code>-B</code> keeps it in the foreground, so that it's report goes to the cron log. A scrub reads every block and compares it with its checksum:</p>
<pre><code># btrfs scrub start -B /
Starting scrub on devid 1
scrub done for af62787a-3caf-46b7-a78d-fca84d5ac031
Scrub started: Mon Nov 2 17:03:08 2026
Status: finished
Duration: 0:00:04
Total to scrub: 1.85GiB
Rate: 473.01MiB/s
Error summary: no errors found</code></pre>
<p>On a single device, btrfs can repair a bad block only from a second copy, and a data block usually has none. The scrub then reports the error and the file that contains it. You can restore the file from a <a href="scram.html">frame</a> with <code>scram restore</code>, or from a <a href="backups.html">backup</a>. A frame is stored on the same disk, so it does not help if the frame contains the same bad block.</p>
<p>The hourly <a href="scram.html">frame</a> is made by the <code>autoframe</code> service.</p>
<h2>What a job sees</h2>
<p>A root job that writes its environment to a file:</p>
<pre><code>* * * * * echo "$PATH|$SHELL|$HOME|$LOGNAME|$(id -un)|$(pwd)" > /tmp/ct/env
# cat /tmp/ct/env
/rod/bin:/rod/profile/bin:/rod/init/bin|/bin/sh|/root|root|root|/root</code></pre>
<p><code>PATH</code> is the value that the <code>run</code> script of <code>crond</code> sets, so <code>fstrim</code> and the busybox applets are found without a full path. The working directory is the home directory of the user.</p>
<p>Whatever a job prints, on standard output or on standard error, is added to the cron log with a timestamp. crond also logs each start.</p>
<pre><code># tail /var/log/crond/current
crond[222]: USER root pid 421 cmd exit 3
2026-11-02_16:59:00.72127 noisy output
2026-11-02_16:59:00.72136 to-stderr
2026-11-02_16:59:00.72151 /bin/sh: line 1: /tmp/ct/ann: Permission denied</code></pre>
<p>The last line comes from a job in <code>/etc/crontabs/dave</code> that tried to write into a directory owned by root. The output of a job that prints on every run should be redirected, or the log fills up. Cron sends no mail.</p>
<h2>Add a job</h2>
<pre><code># echo '30 2 * * * rsync -a /home/ann/ /mnt/backup/ann/' >> /etc/crontabs/root
# cat /etc/crontabs/root</code></pre>
<p>To list a file with the applet, give the directory, because the default <code>/var/spool/cron/crontabs</code> does not exist:</p>
<pre><code># /rod/init/bin/crontab -c /etc/crontabs -l
# minute hour day month weekday command
0 4 * * 0 fstrim -a
0 5 1 * * btrfs scrub start -B /</code></pre>
<h2>Remove or stop</h2>
<p>To remove a job, delete the line or the file. <code>sv down crond</code> stops all jobs until the next boot, and <code>rm /etc/service/crond</code> stops them permanently.</p>
<h2>Limits</h2>
<ul>
<li>A job that was due while the machine was off does not run later.</li>
<li>To run something at boot, use <code>/etc/rc.local</code>, which runs before the services start.</li>
</ul>
<div class="pager"><a href="services.html">← Services</a><a href="network.html">Network →</a></div></article>
</main>
<footer><div class="in"><p>Public domain, CC0 1.0</p><p><a href="https://github.com/uranium-os">GitHub</a> <a href="https://texivi.github.io">Blog</a></p></div></footer>
<script>document.querySelectorAll("pre:not(.term):not(.portrait)").forEach(function(p){var b=document.createElement("button");b.textContent="\u29c9";b.title="Copy";b.onclick=function(){navigator.clipboard.writeText(p.innerText.replace(/\u29c9$/,"").trim());b.textContent="\u2713";setTimeout(function(){b.textContent="\u29c9"},900)};p.appendChild(b)});</script>
<script src="docs.js"></script>
<script src="fun.js"></script>
</body>
</html>