📄 434-437.html
字号:
<HTML>
<HEAD>
<TITLE>Using Linux:Managing Scheduling Services</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0789716232//-->
<!--TITLE=Using Linux//-->
<!--AUTHOR=William Ball//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Que//-->
<!--CHAPTER=26//-->
<!--PAGES=434-437//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="431-434.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="437-439.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading4"></A><FONT COLOR="#000077">The <I>rc</I> Files
</FONT></H4>
<P>This section focuses particular attention on the lines in the <TT>inittab</TT> file that call the <TT>rc</TT> files (refer to Listing 26.1):</P>
<!-- CODE SNIP //-->
<PRE>
l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6
</PRE>
<!-- END CODE SNIP //-->
<P>What is actually being called is the <TT>/etc/rc.d/rc</TT> file. This file is receiving an argument for the run level. At the end of this file, the following commands are called:</P>
<!-- CODE //-->
<PRE>
# Now run the START scripts.
for i in /etc/rc.d/rc$run level.d/S*; do
# Check if the script is there.
[ ! -f $i ] && continue
# Check if the subsystem is already up.
subsys=${i#/etc/rc.d/rc$run level.d/S??}
[ -f /var/lock/subsys/$subsys ] && \
[ -f /var/lock/subsys/${subsys}.init ] && continue
# Bring the subsystem up.
$i start
done
</PRE>
<!-- END CODE //-->
<P>This loop is checking for a directory associated with that particular run level. If the directory exists, each process in that directory is initiated. After all other <TT>rc</TT> files are run, <TT>/etc/rc.d/rc.local</TT> is initiated. This is the best place to put your changes to the system. Note that this file overwrites the <TT>/etc/issue</TT> file at every bootup. So if you want to make changes to the banner that is displayed at logon, make your changes in the <TT>rc.local</TT> file rather than in the <TT>/etc/issue</TT> file.</P>
<P>With <TT>inittab</TT> and <TT>rc</TT> files, you have an excellent set of tools for starting processes at boot time, capturing keystroke events (such as Alt+Ctrl+Delete), and reacting in a proactive manner.</P>
<H3><A NAME="Heading5"></A><FONT COLOR="#000077">Configuring <I>crontab</I> Scheduling Service
</FONT></H3>
<P>Certain processes must be run at a specific time, over and over again. An example of this might be a backup process that is kicked off each night, or a log analyzer that must be run every minute. These processes are run at specific times or on specific days; the rest of the time, they are not running.
</P>
<P><TT>cron</TT> is started from either <TT>rc</TT> or <TT>rc.local</TT> and returns immediately, so there is no need to background this command. <TT>cron</TT> searches <TT>/var/spool/cron</TT> for entries that match users in the <TT>/etc/passwd</TT> file; found entries are loaded into memory. <TT>cron</TT> also searches <TT>/etc/crontab</TT> for system entries.</P>
<P><TT>cron</TT> “wakes up” once a minute and does several things:</P>
<DL>
<DD><B>•</B> It checks the entries that it knows about and runs any commands that are scheduled to run.
<DD><B>•</B> It determines whether the <TT>modtime</TT> on the <TT>cron</TT> directory has changed.
<DD><B>•</B> If the <TT>modtime</TT> on the <TT>cron</TT> directory has changed, <TT>cron</TT> checks each of the files and reloads any that have changed.
</DL>
<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD><FONT SIZE="+1"><B>Do I need to restart cron after a change?</B></FONT>
<BR>Since <TT><B>cron</B></TT> checks for changes every minute, it is unnecessary to restart <TT><B>cron</B></TT> when the <TT><B>cron</B></TT> files are changed.</TABLE>
<H4 ALIGN="LEFT"><A NAME="Heading6"></A><FONT COLOR="#000077">Enabling <I>crontab</I> Service
</FONT></H4>
<P>It is <TT>crontab</TT>’s job to schedule these services. The <TT>cron</TT> daemon reads the <TT>crontab</TT> file; each user can have his or her own version of this file. Flags associated with the <TT>crontab</TT> application specify whether to open <TT>crontab</TT> for listing, editing, or removal.</P>
<P>The syntax for the <TT>crontab</TT> program is as follows:</P>
<!-- CODE SNIP //-->
<PRE>
crontab [-u user] file
crontab [-u user] -l -e -r
</PRE>
<!-- END CODE SNIP //-->
<P>These parameters indicate the following:
</P>
<DL>
<DD><B>•</B> The <TT>-u</TT> option tells the system the name of the user whose <TT>crontab</TT> file is about to be used. If the <TT>-u</TT> option is omitted, the system assumes that you are editing your <TT>crontab</TT>. The switch user (<TT>su</TT>) command can confuse <TT>crontab</TT>, so if you are <TT>su</TT>’ing to someone else, be sure to use the <TT>-u</TT> option.
<DD><B>•</B> The <TT>-l</TT> option tells <TT>crontab</TT> to list the file to standard output (in other words, to list the file).
<DD><B>•</B> The <TT>-e</TT> option tells <TT>crontab</TT> to edit the file. <TT>cron</TT> uses the editor defined by <TT>EDITOR</TT> or by <TT>VISUAL</TT>. If neither is defined, it defaults to <TT>vi</TT>. When the file is exited, it is immediately placed in the correct location and the time stamp is updated.
<DD><B>•</B> The <TT>-r</TT> option removes the specified <TT>crontab</TT> file. If no file is specified, it removes that user’s <TT>crontab</TT> file.
</DL>
<H4 ALIGN="LEFT"><A NAME="Heading7"></A><FONT COLOR="#000077"><I>crontab</I> Entries
</FONT></H4>
<P>Two types of entries are allowed in the <TT>crontab</TT> file:</P>
<DL>
<DD><B>•</B> Environment settings
<DD><B>•</B> Command settings
</DL>
<P>These entries are discussed in the following sections.
</P>
<P><FONT SIZE="+1"><B>Environment Settings</B></FONT></P>
<P><I>Environment settings</I> use the following form:</P>
<!-- CODE SNIP //-->
<PRE>
<I>name = value</I>
</PRE>
<!-- END CODE SNIP //-->
<P><I>cron</I> already knows about several environment settings. For example, <TT>SHELL</TT> is set to <TT>/bin/sh</TT>. Other environment variables, such as <TT>LOGNAME</TT> and <TT>HOME</TT>, are associated with the owner of the file. <TT>SHELL</TT> and <TT>HOME</TT> can be overridden in the script; <TT>LOGNAME</TT> cannot. If <TT>MAILTO</TT> is defined (that is, <TT>MAILTO</TT> actually appears in a line in the <TT>crontab</TT> file and is not set to <TT>“”</TT>), it mails any messages to the specified user. The following shows <TT>MAILTO</TT> set to a specific user:</P>
<!-- CODE SNIP //-->
<PRE>
# mail any output to ’paulc’, no matter whose crontab this
is MAILTO=paulc
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="431-434.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="437-439.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -