Add a section documenting the cron(8) daemon.
This commit is contained in:
parent
52da88130a
commit
5ae7ad9892
Notes:
svn2git
2020-12-08 03:00:23 +00:00
svn path=/head/; revision=17009
1 changed files with 94 additions and 0 deletions
|
@ -417,6 +417,100 @@ exit 0
|
|||
system boot.</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="configtuning-cron">
|
||||
<sect1info>
|
||||
<authorgroup>
|
||||
<author>
|
||||
<firstname>Tom</firstname>
|
||||
<surname>Rhodes</surname>
|
||||
<contrib>Contributed by </contrib>
|
||||
<!-- 20 May 2003 -->
|
||||
</author>
|
||||
</authorgroup>
|
||||
</sect1info>
|
||||
<title>Configuring the <command>cron</command> utility</title>
|
||||
|
||||
<indexterm><primary>Configuring the <command>cron</command> utility</primary></indexterm>
|
||||
|
||||
<para>One of the most useful utilities in FreeBSD is &man.cron.8;. The
|
||||
<command>cron</command> utility runs in the background and constantly
|
||||
checks the <filename>/etc/crontab</filename> file. The <command>cron</command>
|
||||
utility also checks the <filename>/var/cron/tabs</filename> directory, in
|
||||
search of new <filename>crontab</filename> files. These
|
||||
<filename>crontab</filename> files store information about specific
|
||||
functions which <command>cron</command> is supposed to perform at
|
||||
certain times.</para>
|
||||
|
||||
<para>Let us take a look at the <filename>/etc/crontab</filename> file:</para>
|
||||
|
||||
|
||||
<programlisting># /etc/crontab - root's crontab for FreeBSD
|
||||
#
|
||||
# $FreeBSD: src/etc/crontab,v 1.32 2002/11/22 16:13:39 tom Exp $
|
||||
#
|
||||
SHELL=/bin/sh
|
||||
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
|
||||
HOME=/var/log
|
||||
#
|
||||
#minute hour mday month wday who command
|
||||
#
|
||||
*/5 * * * * root /usr/libexec/atrun
|
||||
#
|
||||
# Save some entropy so that /dev/random can re-seed on boot.
|
||||
*/11 * * * * operator /usr/libexec/save-entropy
|
||||
#
|
||||
# Rotate log files every hour, if necessary.
|
||||
0 * * * * root newsyslog
|
||||
#
|
||||
# Perform daily/weekly/monthly maintenance.
|
||||
1 3 * * * root periodic daily
|
||||
15 4 * * 6 root periodic weekly
|
||||
30 5 1 * * root periodic monthly
|
||||
#
|
||||
# Adjust the time zone if the CMOS clock keeps local time, as opposed to
|
||||
# UTC time. See adjkerntz(8) for details.
|
||||
1,31 0-5 * * * root adjkerntz -a</programlisting>
|
||||
|
||||
<para>Like most of the configuration files in FreeBSD, the <quote>#</quote>
|
||||
character represents a comment. Notice we have several lines here. Each
|
||||
line has seven fields. The first five of these fields hold time information,
|
||||
listed in minute, hour, day, month, and the day of the week. Some of these
|
||||
fields have a <quote>*</quote> character, which represents <quote>every</quote>.
|
||||
Thus, if we look at the periodic monthly listing, we can see that it is set to
|
||||
run at minute thirty, hour five, on the first day of every month. Always
|
||||
remember that time is in the twenty-four hour clock format. You can also see
|
||||
that this command is set to be run as <username>root</username>.</para>
|
||||
|
||||
<para>This is the basic set up for every <filename>crontab</filename> file,
|
||||
although there is one thing different about this one. Field number six, where
|
||||
we specified the username, only exists in the <filename>/etc/contrab</filename>
|
||||
file. If you ever write your own <filename>crontab</filename>, which I know you
|
||||
will if your reading this, use of this field should be avoided.</para>
|
||||
|
||||
<note><para>The <command>cron</command> utility cannot read shell start up files,
|
||||
therefor absolute paths need to be used in the
|
||||
<filename>crontab</filename>.</para></note>
|
||||
|
||||
<para>The final field here will define the action to be performed. This field can
|
||||
be have any valid command, or shell script. So if you want a list of actions to
|
||||
be performed, you can write a shell script to execute them. Then define this shell
|
||||
script in your <filename>crontab</filename>.</para>
|
||||
|
||||
<sect2 id="configtuning-installcrontab">
|
||||
<title>Installing a <filename>crontab</filename></title>
|
||||
|
||||
<para>To install your freshly written <filename>crontab</filename>, just
|
||||
use the <command>crontab</command> utility. The most common usage is:</para>
|
||||
|
||||
<screen>&prompt.root; <userinput>crontab crontab</userinput></screen>
|
||||
|
||||
<para>There is also an option to list installed <filename>crontab</filename> files,
|
||||
just pass the <option>-l</option> to <command>crontab</command> and look
|
||||
over the output.</para>
|
||||
|
||||
</sect2>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="configtuning-rcNG">
|
||||
<sect1info>
|
||||
<authorgroup>
|
||||
|
|
Loading…
Reference in a new issue