Added extra/crond.service for systemd
[dcron.git] / crond.8
blob1582235417328463f059d7a956280cd90c007f63
1 .TH CROND 8 "1 May 2011"
2 .SH NAME
3 .PP
4 crond - dillon's lightweight cron daemon
5 .SH SYNOPSIS
6 .PP
7 \f[B]crond [-s dir] [-c dir] [-t dir] [-m user\@host] [-M mailhandler] [-S|-L file] [-l loglevel] [-b|-f|-d]\f[]
8 .SH OPTIONS
9 .PP
10 \f[B]crond\f[] is a background daemon that parses individual
11 crontab files and executes commands on behalf of the users in
12 question.
13 .TP
14 .B -s dir
15 directory of system crontabs (defaults to /etc/cron.d)
16 .RS
17 .RE
18 .TP
19 .B -c dir
20 directory of per-user crontabs (defaults to
21 /var/spool/cron/crontabs)
22 .RS
23 .RE
24 .TP
25 .B -t dir
26 directory of timestamps for \@freq and FREQ=\&... jobs (defaults to
27 /var/spool/cron/cronstamps)
28 .RS
29 .RE
30 .TP
31 .B -m user\@host
32 where should the output of cronjobs be directed? (defaults to local
33 user) Some mail handlers (like msmtp) can't route mail to local
34 users.
35 If that's what you're using, then you should supply a remote
36 address using this switch.
37 Cron output for all users will be directed to that address.
38 Alternatively, you could supply a different mail handler using the
39 -M switch, to log or otherwise process the messages instead of
40 mailing them.
41 Alternatively, you could just direct the stdout and stderr of your
42 cron jobs to /dev/null.
43 .RS
44 .RE
45 .TP
46 .B -M mailhandler
47 Any output that cronjobs print to stdout or stderr gets formatted
48 as an email and piped to \f[C]/usr/sbin/sendmail\ -t\ -oem\ -i\f[].
49 Attempts to mail this are also logged.
50 This switch permits the user to substitute a different mailhandler,
51 or a script, for sendmail.
52 That custom mailhandler is called with no arguments, and with the
53 mail headers and cronjob output supplied to stdin.
54 When a custom mailhandler is used, mailing is no longer logged
55 (have your mailhandler do that if you want it).
56 When cron jobs generate no stdout or stderr, nothing is sent to
57 either sendmail or a custom mailhandler.
58 .RS
59 .RE
60 .TP
61 .B -S
62 log events to syslog, using syslog facility LOG_CRON and identity
63 `crond' (this is the default behavior).
64 .RS
65 .RE
66 .TP
67 .B -L file
68 log to specified file instead of syslog.
69 .RS
70 .RE
71 .TP
72 .B -l loglevel
73 log events at the specified, or more important, loglevels.
74 The default is `notice'.
75 Valid level names are as described in logger(1) and syslog(3):
76 alert, crit, debug, emerg, err, error (deprecated synonym for err),
77 info, notice, panic (deprecated synonym for emerg), warning, warn
78 (deprecated synonym for warning).
79 .RS
80 .RE
81 .TP
82 .B -b
83 run \f[B]crond\f[] in the background (default unless -d or -f is
84 specified)
85 .RS
86 .RE
87 .TP
88 .B -f
89 run \f[B]crond\f[] in the foreground.
90 All log messages are sent to stderr instead of syslog or a -L file.
91 .RS
92 .RE
93 .TP
94 .B -d
95 turn on debugging.
96 This option sets the logging level to `debug' and causes
97 \f[B]crond\f[] to run in the foreground.
98 .RS
99 .RE
100 .SH DESCRIPTION
102 \f[B]crond\f[] is responsible for scanning the crontab files and
103 running their commands at the appropriate time.
104 It always synchronizes to the top of the minute, matching the
105 current time against its internal list of parsed crontabs.
106 That list is stored so that it can be scanned very quickly, and
107 \f[B]crond\f[] can deal with several hundred crontabs with several
108 thousand entries without using noticeable CPU.
110 Cron jobs are not re-executed if a previous instance of them is
111 still running.
112 For example, if you have a crontab command \f[C]sleep\ 70\f[], that
113 you request to be run every minute, \f[B]crond\f[] will skip this
114 job when it sees it is still running.
115 So the job won't be run more frequently than once every two
116 minutes.
117 If you do not like this feature, you can run your commands in the
118 background with an \f[C]&\f[].
120 \f[B]crond\f[] automatically detects when the clock has been
121 changed, during its per-minute scans.
122 Backwards time-changes of an hour or less won't re-run cron jobs
123 from the intervening period.
124 \f[B]crond\f[] will effectively sleep until it catches back up to
125 the original time.
126 Forwards time-changes of an hour or less (or if the computer is
127 suspended and resumed again within an hour) will run any missed
128 jobs exactly once.
129 Changes greater than an hour in either direction cause
130 \f[B]crond\f[] to re-calculate when jobs should be run, and not
131 attempt to execute any missed commands.
132 This is effectively the same as if \f[B]crond\f[] had been stopped
133 and re-started.
135 For example, suppose it's 10 am, and a job is scheduled to run
136 every day at 10:30 am.
137 If you set the system's clock forward to 11 am, crond will
138 immediately run the 10:30 job.
139 If on the other hand you set the system's clock forward to noon,
140 the 10:30 am job will be skipped until the next day.
141 Jobs scheduled using \@daily and the like work differently; see
142 crontab(1) for details.
144 \f[B]crond\f[] has a number of built in limitations to reduce the
145 chance of it being ill-used.
146 Potentially infinite loops during parsing are dealt with via a
147 failsafe counter, and non-root crontabs are limited to 256 crontab
148 entries.
149 Crontab lines may not be longer than 1024 characters, including the
150 newline.
152 Whenever \f[B]crond\f[] must run a job, it first creates a
153 daemon-owned temporary file O_EXCL and O_APPEND to store any
154 output, then fork()s and changes its user and group permissions to
155 match that of the user the job is being run for, then
156 \f[B]exec\f[]s \f[B]/bin/sh -c \f[] to run the job.
157 The temporary file remains under the ownership of the daemon to
158 prevent the user from tampering with it.
159 Upon job completion, \f[B]crond\f[] verifies the secureness of the
160 mail file and, if it has been appended to, mails the file to the
161 specified address.
162 The \f[B]sendmail\f[] program (or custom mail handler, if supplied)
163 is run under the user's uid to prevent mail related security holes.
165 When a user edits their crontab, \f[B]crontab\f[] first copies the
166 crontab to a user owned file before running the user's preferred
167 editor.
168 The suid \f[B]crontab\f[] keeps an open descriptor to the file
169 which it later uses to copy the file back, thereby ensuring the
170 user has not tampered with the file type.
172 \f[B]crontab\f[] notifies \f[B]crond\f[] that a user's crontab file
173 has been modified (or created or deleted) through the
174 \[lq]cron.update\[rq] file, which resides in the per-user crontabs
175 directory (usually /var/spool/cron/crontabs).
176 \f[B]crontab\f[] appends the filename of the modified crontab file
177 to \[lq]cron.update\[rq]; and \f[B]crond\f[] inspects this file to
178 determine when to reparse or otherwise update its internal list of
179 parsed crontabs.
181 Whenever a \[lq]cron.update\[rq] file is seen, \f[B]crond\f[] also
182 re-reads timestamp files from its timestamp directory (usually
183 /var/spool/cron/cronstamps).
184 Normally these will just mirror \f[B]crond\f[]'s own internal
185 representations, but this mechanism could be used to manually
186 notify \f[B]crond\f[] that you've externally updated the
187 timestamps.
189 The \[lq]cron.update\[rq] file can also be used to ask
190 \f[B]crond\f[] to schedule a \[lq]named\[rq] cron job.
191 To do this, append a line of the form:
194 \f[C]
195 clio\ job1\ !job2
196 \f[]
199 to \[lq]cron.update\[rq].
200 This request that user clio's job1 should be scheduled (waiting
201 first for the successful completion of any jobs named in job1's
202 AFTER= tag), and job2 should also be scheduled (without waiting for
203 other jobs).
204 See crontab(1) for more about tags and named jobs.
206 The directory of per-user crontabs is re-parsed once every hour in
207 any case.
208 Any crontabs in the system directory (usually /etc/cron.d) are
209 parsed at the same time.
210 This directory can be used by packaging systems.
211 When you install a package foo, it might write its own foo-specific
212 crontab to /etc/cron.d/foo.
214 The superuser has a per-user crontab along with other users.
215 It usually resides at /var/spool/cron/crontabs/root.
217 Users can only have a crontab if they have an entry in /etc/passwd;
218 however they do not need to have login shell privileges.
219 Cron jobs are always run under /bin/sh; see crontab(1) for more
220 details.
222 Unlike \f[B]crontab\f[], the \f[B]crond\f[] program does not keep
223 open descriptors to crontab files while running their jobs, as this
224 could cause \f[B]crond\f[] to run out of descriptors.
225 .SH SEE ALSO
227 \f[B]crontab\f[](1)
228 .SH AUTHORS
230 Matthew Dillon (dillon\@apollo.backplane.com): original
231 developer
232 .PD 0
235 Jim Pryor (profjim\@jimpryor.net): current
236 developer