man-pages/man8/cron.8.html
2021-03-31 01:06:50 +01:00

416 lines
12 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of CRON</TITLE>
</HEAD><BODY>
<H1>CRON</H1>
Section: Maintenance Commands (8)<BR>Updated: 19 April 2010<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
cron - daemon to execute scheduled commands (Vixie Cron)
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
cron
[<B>-f</B>]
[<B>-l</B>]
[<B>-L</B>
<I>loglevel</I>]
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<I>cron</I>
is started automatically from /etc/init.d on entering multi-user
runlevels.
<A NAME="lbAE">&nbsp;</A>
<H2>OPTIONS</H2>
<DL COMPACT>
<DT id="1"><B>-f</B>
<DD>
Stay in foreground mode, don't daemonize.
<DT id="2"><B>-l</B>
<DD>
Enable LSB compliant names for /etc/cron.d files. This setting, however, does
not affect the parsing of files under /etc/cron.hourly, /etc/cron.daily,
/etc/cron.weekly or /etc/cron.monthly.
<DT id="3"><B>-n</B>
<DD>
Include the FQDN in the subject when sending mails. By default, cron will
abbreviate the hostname.
<DT id="4"><B>-L loglevel</B>
<DD>
Tell cron what to log about <B>jobs</B> (errors are logged regardless of this
value) as the sum of the following values:
<BR>
<DL COMPACT><DT id="5"><DD>
<DL COMPACT>
<DT id="6"><B>1</B><DD>
will log the start of all cron jobs
<DT id="7"><B>2</B><DD>
will log the end of all cron jobs
<DT id="8"><B>4</B><DD>
will log all failed jobs (exit status != 0)
<DT id="9"><B>8</B><DD>
will log the process number of all cron jobs
</DL>
</DL>
<DT id="10"><DD>
The default is to log the start of all jobs (1).
Logging will be disabled if
<I>levels</I>
is set to zero (0).
A value of fifteen (15) will select all options.
</DL>
<A NAME="lbAF">&nbsp;</A>
<H2>NOTES</H2>
<P>
<I>cron</I>
searches its spool area (/var/spool/cron/crontabs) for crontab
files (which are named after accounts in
/etc/passwd); crontabs found are loaded into memory. Note that
crontabs in this directory should not be accessed directly -
the
<I>crontab</I>
command should be used to access and update them.
<P>
<I>cron</I>
also reads /etc/crontab, which is in a slightly different format (see
<I><A HREF="/cgi-bin/man/man2html?5+crontab">crontab</A></I>(5)).
In Debian, the content of /etc/crontab is predefined
to run programs under /etc/cron.hourly, /etc/cron.daily,
/etc/cron.weekly and /etc/cron.monthly. This configuration is specific to
Debian, see the note under
<B>DEBIAN SPECIFIC</B>
below.
<P>
Additionally, in Debian,
<I>cron</I>
reads the files in the /etc/cron.d directory.
<I>cron</I>
treats the files in /etc/cron.d as in the same way as the /etc/crontab
file (they follow the special format of that file,
i.e. they include the
<I>user</I>
field). However, they are independent of /etc/crontab: they do not, for
example, inherit environment variable settings from it. This change is
specific to Debian see the note under
<B>DEBIAN SPECIFIC</B>
below.
<P>
Like /etc/crontab, the files in the /etc/cron.d directory are
monitored for changes.
In general, the system administrator should not use /etc/cron.d/,
but use the standard system crontab /etc/crontab.
<P>
/etc/crontab and the files in /etc/cron.d must be owned by root, and must not
be group- or other-writable. In contrast to the spool area, the files
under /etc/cron.d or the files under /etc/cron.hourly, /etc/cron.daily,
/etc/cron.weekly and /etc/cron.monthly may also be symlinks,
provided that both the symlink and the file it points to are owned by root.
The files under /etc/cron.d do not need to be executable, while the files
under /etc/cron.hourly, /etc/cron.daily,
/etc/cron.weekly and /etc/cron.monthly do, as they are run by
<I>run-parts</I>
(see
<I><A HREF="/cgi-bin/man/man2html?8+run-parts">run-parts</A></I>(8)
for more information).
<P>
<I>cron</I>
then wakes up every minute, examining all stored crontabs, checking
each command to see if it should be run in the current minute. When
executing commands, any output is mailed to the owner of the crontab
(or to the user named in the MAILTO environment variable in the
crontab, if such exists). The children copies of cron running these
processes have their name coerced to uppercase, as will be seen in the
syslog and ps output.
<P>
Additionally,
<I>cron</I>
checks each minute to see if its spool directory's modtime (or the modtime
on the
<I>/etc/crontab</I>
file)
has changed, and if it has,
<I>cron</I>
will then examine the modtime on all crontabs and reload those which have
changed. Thus
<I>cron</I>
need not be restarted whenever a crontab file is modified. Note that the
<I><A HREF="/cgi-bin/man/man2html?1+crontab">crontab</A></I>(1)
command updates the modtime of the spool directory whenever it changes a
crontab.
<P>
Special considerations exist when the clock is changed by less than 3
hours, for example at the beginning and end of daylight savings
time. If the time has moved forwards, those jobs which would have
run in the time that was skipped will be run soon after the change.
Conversely, if the time has moved backwards by less than 3 hours,
those jobs that fall into the repeated time will not be re-run.
<P>
Only jobs that run at a particular time (not specified as
@hourly, nor with '*' in the hour or minute specifier) are
affected. Jobs which are specified with wildcards are run based on the
new time immediately.
<P>
Clock changes of more than 3 hours are considered to be corrections to
the clock, and the new time is used immediately.
<P>
<I>cron</I>
logs its action to the syslog facility 'cron', and logging may be
controlled using the standard
<I><A HREF="/cgi-bin/man/man2html?8+syslogd">syslogd</A></I>(8)
facility.
<A NAME="lbAG">&nbsp;</A>
<H2>ENVIRONMENT</H2>
If configured in
<I>/etc/default/cron</I>
in Debian systems, the
<I>cron</I>
daemon localisation settings environment can be managed through the use of
<I>/etc/environment</I>
or through the use of
<I>/etc/default/locale</I>
with values from the latter overriding values from the former. These
files are read and they will be used to setup the LANG, LC_ALL, and
LC_CTYPE environment variables. These variables are then used to set the
charset of mails, which defaults to 'C'.
<P>
This does
<B>NOT</B>
affect the environment of tasks running under cron. For more information
on how to modify the environment of tasks, consult
<I><A HREF="/cgi-bin/man/man2html?5+crontab">crontab</A></I>(5).
<P>
The daemon will use, if present, the definition from
<I>/etc/timezone</I>
for the timezone.
<P>
The environment can be redefined in user's crontab definitions but
<I>cron</I>
will only handle tasks in a single timezone.
<P>
<A NAME="lbAH">&nbsp;</A>
<H2>DEBIAN SPECIFIC</H2>
<P>
Debian introduces some changes to
<I>cron</I>
that were not originally available upstream. The most significant
changes introduced are:
<P>
<DL COMPACT>
<DT id="11">---<DD>
Support for /etc/cron.{hourly,daily,weekly,monthly} via /etc/crontab,
<DT id="12">---<DD>
Support for /etc/cron.d (drop-in dir for package crontabs),
<DT id="13">---<DD>
PAM support,
<DT id="14">---<DD>
SELinux support,
<DT id="15">---<DD>
auditlog support,
<DT id="16">---<DD>
DST and other time-related changes/fixes,
<DT id="17">---<DD>
SGID <A HREF="/cgi-bin/man/man2html?1+crontab">crontab</A>(1) instead of SUID root,
<DT id="18">---<DD>
Debian-specific file locations and commands,
<DT id="19">---<DD>
Debian-specific configuration (/etc/default/cron),
<DT id="20">---<DD>
numerous other smaller features and fixes.
<P>
</DL>
<P>
Support for /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly and
/etc/cron.monthly is provided in Debian through the default setting
of the /etc/crontab file (see the system-wide example in
<I><A HREF="/cgi-bin/man/man2html?5+crontab">crontab</A></I>(5)).
The default system-wide crontab contains four tasks: run every hour, every
day, every week and every month. Each of these tasks will execute
<B>run-parts</B>
providing each one of the directories as an argument.
These tasks are disabled if
<B>anacron</B>
is installed (except for the hourly task) to prevent conflicts between
both daemons.
<P>
As described above, the files under these directories have to pass
some sanity checks including the following: be executable, be owned by root,
not be writable by group or other and, if symlinks, point to files owned by
root. Additionally, the file names must conform to the filename requirements
of
<B>run-parts</B>:
they must be entirely made up of letters, digits and can only contain the
special signs underscores ('_') and hyphens ('-'). Any file that does
not conform to these requirements will not be executed by
<B>run-parts</B>.
For example, any file containing dots will be ignored.
This is done to prevent cron from running any of the files
that are left by the Debian package management system when handling files in
/etc/cron.d/ as configuration files (i.e. files ending in
.dpkg-dist, .dpkg-orig, .dpkg-old, and .dpkg-new).
<P>
This feature can be used by system administrators and packages to include
tasks that will be run at defined intervals. Files created by packages in these
directories should be named after the package that supplies them.
<P>
<P>
Support for /etc/cron.d is included in the
<I>cron</I>
daemon itself, which handles this location as the system-wide crontab spool.
This directory can contain any file defining tasks following the format
used in /etc/crontab, i.e. unlike the user cron spool, these files must
provide the username to run the task as in the task definition.
<P>
Files in this directory have to be owned by root, do not need to be executable
(they are configuration files, just like /etc/crontab) and
must conform to the same naming convention as used by
<I><A HREF="/cgi-bin/man/man2html?8+run-parts">run-parts</A></I>(8) :
they
must consist solely of upper- and lower-case letters, digits, underscores,
and hyphens. This means that they
<B>cannot</B>
contain any dots.
If the
<B>-l</B>
option is specified to
<I>cron</I>
(this option can be setup through /etc/default/cron, see below), then they must
conform to the LSB namespace specification, exactly as in the
<B>--lsbsysinit</B>
option in
<I>run-parts</I>.
<P>
The intended purpose of this feature is to allow packages that require
finer control of their scheduling than the
/etc/cron.{hourly,daily,weekly,monthly}
directories to add a crontab file to /etc/cron.d. Such files
should be named after the package that supplies them.
<P>
<P>
Also, the default configuration of
<I>cron</I>
is controlled by
<I>/etc/default/cron</I>
which is read by the init.d script that launches the
<I>cron</I>
daemon. This file determines whether
<I>cron</I>
will read the system's environment variables and makes it possible to add
additional options to the
<I>cron</I>
program before it is executed, either to configure its logging or to define how
it will treat the files under /etc/cron.d.
<P>
<A NAME="lbAI">&nbsp;</A>
<H2>SEE ALSO</H2>
<A HREF="/cgi-bin/man/man2html?1+crontab">crontab</A>(1), <A HREF="/cgi-bin/man/man2html?5+crontab">crontab</A>(5), <A HREF="/cgi-bin/man/man2html?8+run-parts">run-parts</A>(8)
<A NAME="lbAJ">&nbsp;</A>
<H2>AUTHOR</H2>
Paul Vixie &lt;<A HREF="mailto:paul@vix.com">paul@vix.com</A>&gt; is the author of
<I>cron</I>
and original creator of this manual page. This page has also been modified for
Debian by Steve Greenland, Javier Fernandez-Sanguino and Christian Kastner.
<P>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="21"><A HREF="#lbAB">NAME</A><DD>
<DT id="22"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="23"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="24"><A HREF="#lbAE">OPTIONS</A><DD>
<DT id="25"><A HREF="#lbAF">NOTES</A><DD>
<DT id="26"><A HREF="#lbAG">ENVIRONMENT</A><DD>
<DT id="27"><A HREF="#lbAH">DEBIAN SPECIFIC</A><DD>
<DT id="28"><A HREF="#lbAI">SEE ALSO</A><DD>
<DT id="29"><A HREF="#lbAJ">AUTHOR</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:06:11 GMT, March 31, 2021
</BODY>
</HTML>