⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configtuning-cron.html

📁 FreeBSD操作系统的详细使用手册
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>Configuring the cron Utility</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD Handbook" href="index.html" /><link rel="UP" title="Configuration and Tuning" href="config-tuning.html" /><link rel="PREVIOUS" title="Starting Services"href="configtuning-starting-services.html" /><link rel="NEXT" title="Using rc under FreeBSD 5.X" href="configtuning-rcng.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD Handbook</th></tr><tr><td width="10%" align="left" valign="bottom"><ahref="configtuning-starting-services.html" accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 11 Configuration and Tuning</td><td width="10%" align="right" valign="bottom"><a href="configtuning-rcng.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="CONFIGTUNING-CRON" name="CONFIGTUNING-CRON">11.6 Configuring the<tt class="COMMAND">cron</tt> Utility</a></h1><i class="AUTHORGROUP"><span class="CONTRIB">Contributed by</span> Tom Rhodes.</i> <p>One of the most useful utilities in FreeBSD is <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=cron&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">cron</span>(8)</span></a>. The <ttclass="COMMAND">cron</tt> utility runs in the background and constantly checks the <ttclass="FILENAME">/etc/crontab</tt> file. The <tt class="COMMAND">cron</tt> utility alsochecks the <tt class="FILENAME">/var/cron/tabs</tt> directory, in search of new <ttclass="FILENAME">crontab</tt> files. These <tt class="FILENAME">crontab</tt> files storeinformation about specific functions which <tt class="COMMAND">cron</tt> is supposed toperform at certain times.</p><p>The <tt class="COMMAND">cron</tt> utility uses two different types of configurationfiles, the system crontab and user crontabs. The only difference between these twoformats is the sixth field. In the system crontab, the sixth field is the name of a userfor the command to run as. This gives the system crontab the ability to run commands asany user. In a user crontab, the sixth field is the command to run, and all commands runas the user who created the crontab; this is an important security feature.</p><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> User crontabs allow individual users to schedule tasks without the needfor root privileges. Commands in a user's crontab run with the permissions of the userwho owns the crontab.</p><p>The <tt class="USERNAME">root</tt> user can have a user crontab just like any otheruser. This one is different from <tt class="FILENAME">/etc/crontab</tt> (the systemcrontab). Because of the system crontab, there's usually no need to create a user crontabfor <tt class="USERNAME">root</tt>.</p></blockquote></div><p>Let us take a look at the <tt class="FILENAME">/etc/crontab</tt> file (the systemcrontab):</p><pre class="PROGRAMLISTING"># /etc/crontab - root's crontab for FreeBSD## $FreeBSD: src/etc/crontab,v 1.32 2002/11/22 16:13:39 tom Exp $# <a id="CO-COMMENTS" name="CO-COMMENTS"><img src="./imagelib/callouts/1.png" hspace="0"vspace="0" border="0" alt="(1)" /></a>#SHELL=/bin/shPATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin <a id="CO-ENV" name="CO-ENV"><imgsrc="./imagelib/callouts/2.png" hspace="0" vspace="0" border="0" alt="(2)" /></a>HOME=/var/log###minute hour    mday    month   wday    who command <a id="CO-FIELD-DESCR"name="CO-FIELD-DESCR"><img src="./imagelib/callouts/3.png" hspace="0" vspace="0"border="0" alt="(3)" /></a>##*/5 *   *   *   *   root    /usr/libexec/atrun <a id="CO-MAIN" name="CO-MAIN"><imgsrc="./imagelib/callouts/4.png" hspace="0" vspace="0" border="0" alt="(4)" /></a></pre><div class="CALLOUTLIST"><dl compact="COMPACT"><dt><a href="configtuning-cron.html#CO-COMMENTS"><img src="./imagelib/callouts/1.png"hspace="0" vspace="0" border="0" alt="(1)" /></a></dt><dd>Like most FreeBSD configuration files, the <var class="LITERAL">#</var> characterrepresents a comment. A comment can be placed in the file as a reminder of what and why adesired action is performed. Comments cannot be on the same line as a command or elsethey will be interpreted as part of the command; they must be on a new line. Blank linesare ignored.</dd><dt><a href="configtuning-cron.html#CO-ENV"><img src="./imagelib/callouts/2.png"hspace="0" vspace="0" border="0" alt="(2)" /></a></dt><dd>First, the environment must be defined. The equals (<var class="LITERAL">=</var>)character is used to define any environment settings, as with this example where it isused for the <tt class="ENVAR">SHELL</tt>, <tt class="ENVAR">PATH</tt>, and <ttclass="ENVAR">HOME</tt> options. If the shell line is omitted, <ttclass="COMMAND">cron</tt> will use the default, which is <tt class="COMMAND">sh</tt>. Ifthe <tt class="ENVAR">PATH</tt> variable is omitted, no default will be used and filelocations will need to be absolute. If <tt class="ENVAR">HOME</tt> is omitted, <ttclass="COMMAND">cron</tt> will use the invoking users home directory.</dd><dt><a href="configtuning-cron.html#CO-FIELD-DESCR"><img src="./imagelib/callouts/3.png"hspace="0" vspace="0" border="0" alt="(3)" /></a></dt><dd>This line defines a total of seven fields. Listed here are the values <varclass="LITERAL">minute</var>, <var class="LITERAL">hour</var>, <varclass="LITERAL">mday</var>, <var class="LITERAL">month</var>, <varclass="LITERAL">wday</var>, <var class="LITERAL">who</var>, and <varclass="LITERAL">command</var>. These are almost all self explanatory. <varclass="LITERAL">minute</var> is the time in minutes the command will be run. <varclass="LITERAL">hour</var> is similar to the <var class="LITERAL">minute</var> option,just in hours. <var class="LITERAL">mday</var> stands for day of the month. <varclass="LITERAL">month</var> is similar to <var class="LITERAL">hour</var> and <varclass="LITERAL">minute</var>, as it designates the month. The <varclass="LITERAL">wday</var> option stands for day of the week. All these fields must benumeric values, and follow the twenty-four hour clock. The <var class="LITERAL">who</var>field is special, and only exists in the <tt class="FILENAME">/etc/crontab</tt> file.This field specifies which user the command should be run as. When a user installs his orher <tt class="FILENAME">crontab</tt> file, they will not have this option. Finally, the<var class="LITERAL">command</var> option is listed. This is the last field, so naturallyit should designate the command to be executed.</dd><dt><a href="configtuning-cron.html#CO-MAIN"><img src="./imagelib/callouts/4.png"hspace="0" vspace="0" border="0" alt="(4)" /></a></dt><dd>This last line will define the values discussed above. Notice here we have a <varclass="LITERAL">*/5</var> listing, followed by several more <var class="LITERAL">*</var>characters. These <var class="LITERAL">*</var> characters mean ``first-last'', and can beinterpreted as <span class="emphasis"><i class="EMPHASIS">every</i></span> time. So,judging by this line, it is apparent that the <tt class="COMMAND">atrun</tt> command isto be invoked by <tt class="USERNAME">root</tt> every five minutes regardless of what dayor month it is. For more information on the <tt class="COMMAND">atrun</tt> command, seethe <a href="http://www.FreeBSD.org/cgi/man.cgi?query=atrun&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">atrun</span>(8)</span></a> manualpage.</dd><dd><p>Commands can have any number of flags passed to them; however, commands which extendto multiple lines need to be broken with the backslash ``\'' continuation character.</p></dd></dl></div><p>This is the basic set up for every <tt class="FILENAME">crontab</tt> file, althoughthere is one thing different about this one. Field number six, where we specified theusername, only exists in the system <tt class="FILENAME">/etc/crontab</tt> file. Thisfield should be omitted for individual user <tt class="FILENAME">crontab</tt> files.</p><div class="SECT2"><h2 class="SECT2"><a id="CONFIGTUNING-INSTALLCRONTAB"name="CONFIGTUNING-INSTALLCRONTAB">11.6.1 Installing a Crontab</a></h2><div class="IMPORTANT"><blockquote class="IMPORTANT"><p><b>Important:</b> You must not use the procedure described here to edit/install thesystem crontab. Simply use your favorite editor: the <tt class="COMMAND">cron</tt>utility will notice that the file has changed and immediately begin using the updatedversion. See <ahref="../../../../doc/en_US.ISO8859-1/books/faq/admin.html#ROOT-NOT-FOUND-CRON-ERRORS"target="_top">this FAQ entry</a> for more information.</p></blockquote></div><p>To install a freshly written user <tt class="FILENAME">crontab</tt>, first use yourfavorite editor to create a file in the proper format, and then use the <ttclass="COMMAND">crontab</tt> utility. The most common usage is:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbd class="USERINPUT">crontab crontab-file</kbd></pre><p>In this example, <tt class="FILENAME">crontab-file</tt> is the filename of a <ttclass="FILENAME">crontab</tt> that was previously created.</p><p>There is also an option to list installed <tt class="FILENAME">crontab</tt> files:just pass the <var class="OPTION">-l</var> option to <tt class="COMMAND">crontab</tt> andlook over the output.</p><p>For users who wish to begin their own crontab file from scratch, without the use of atemplate, the <tt class="COMMAND">crontab -e</tt> option is available. This will invokethe selected editor with an empty file. When the file is saved, it will be automaticallyinstalled by the <tt class="COMMAND">crontab</tt> command.</p><p>If you later want to remove your user <tt class="FILENAME">crontab</tt> completely,use <tt class="COMMAND">crontab</tt> with the <var class="OPTION">-r</var> option.</p></div></div><div class="NAVFOOTER"><hr align="LEFT" width="100%" /><table summary="Footer navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="configtuning-starting-services.html"accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html"accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="configtuning-rcng.html"accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Starting Services</td><td width="34%" align="center" valign="top"><a href="config-tuning.html"accesskey="U">Up</a></td><td width="33%" align="right" valign="top">Using rc under FreeBSD 5.X</td></tr></table></div><p align="center"><small>This, and other documents, can be downloaded from <ahref="ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/">ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/</a>.</small></p><p align="center"><small>For questions about FreeBSD, read the <ahref="http://www.FreeBSD.org/docs.html">documentation</a> before contacting &#60;<ahref="mailto:questions@FreeBSD.org">questions@FreeBSD.org</a>&#62;.<br />For questions about this documentation, e-mail &#60;<ahref="mailto:doc@FreeBSD.org">doc@FreeBSD.org</a>&#62;.</small></p></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -