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

📄 386-388.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Special Edition Using Linux, Fourth Edition:Managing Multiple Processes</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=0789717468//-->

<!--TITLE=Special Edition Using Linux, Fourth Edition//-->

<!--AUTHOR=Jack Tackett//-->

<!--AUTHOR=Jr.//-->

<!--AUTHOR=Steve Burnett//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Que//-->

<!--CHAPTER=19//-->

<!--PAGES=386-388//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="384-386.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="388-390.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<P>The following example performs its job at 1:23 a.m. If you&#146;re working in the wee hours of the morning before 1:23 a.m. (that is, between midnight and 1:23 a.m.), the command is done today, at 1:23 a.m. Otherwise, it&#146;s done at 1:23 a.m. the following day. The job prints all files in the directory /usr/sales/reports and sends a user named boss some mail announcing that the print job was done at 1:23 a.m. Type the following commands on the terminal, pressing &lt;Return&gt; at the end of each line. After you enter each line, press &lt;Ctrl-d&gt; to finish the command.

</P>

<!-- CODE SNIP //-->

<PRE>

<B>at 1:23</B>

<B>lp /usr/sales/reports/*</B>

<B>echo &#147;Files printed, Boss!&#148; | mail -s&#147;Job done&#148; boss</B>

</PRE>

<!-- END CODE SNIP //-->

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B><TT>cron</TT> jobs, discussed later in this chapter, are the most commonly used mechanisms for running automated system administration jobs under Linux. However, you must be the root user to create and edit <TT>cron</TT> job entries. The <TT>at</TT> command allows anyone to run tasks even if he or she does not have root privileges.<HR></FONT>

</BLOCKQUOTE>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR>&#149; <B>See</B> &#147;Setting the Terminal Environment,&#148; <B>p. 341</B><HR></FONT>

</BLOCKQUOTE>

<P>Commands to be scheduled by <TT>at</TT> are entered as a list of commands on the line following the <TT>at</TT> command.</P>

<P>After you terminate the <TT>at</TT> command, you see a display similar to the following:</P>

<!-- CODE SNIP //-->

<PRE>

job 756603300.a at Tues Jan 21 01:23:00 1997

</PRE>

<!-- END CODE SNIP //-->

<P>This response indicates that the job will execute at 1:23 as specified. The job number, 756603300.a, identifies the job. If you decide you want to cancel the job, do so by using the job number associated with it, like so:

</P>

<!-- CODE SNIP //-->

<PRE>

at -d 756603300.a

</PRE>

<!-- END CODE SNIP //-->

<P>If you have several commands you want to schedule by using <TT>at</TT>, it&#146;s best to put them in a file. If the filename is getdone, for example, and you want to schedule the commands for 10 a.m., type either</P>

<!-- CODE SNIP //-->

<PRE>

<B>at 10:00 &lt; getdone</B>

</PRE>

<!-- END CODE SNIP //-->

<P>or

</P>

<!-- CODE SNIP //-->

<PRE>

<B>at 10:00 -f getdone</B>

</PRE>

<!-- END CODE SNIP //-->

<P>Remember that the less-than symbol (&lt;) indicates the use of the contents of the getdone file as input to the <TT>at</TT> command. The <TT>-f</TT> option allows you to specify the command file without using redirection.</P>

<P>You can also specify a date for an <TT>at</TT> job. For example, to schedule a job at 5 p.m. on January 24, enter these commands:</P>

<!-- CODE SNIP //-->

<PRE>

<B>at 17:00 Jan 24</B>

<B>lp /usr/sales/reports/*</B>

<B>echo &#147;Files printed, Boss!&#148; | mail -s&#147;Job done&#148; boss</B>

</PRE>

<!-- END CODE SNIP //-->

<P>The jobs you schedule with <TT>at</TT> are put into a queue that the operating system checks periodically. You don&#146;t have to be logged in for the job to be executed. The <TT>at</TT> command always runs in the background, freeing resources but still accomplishing the job. Any output produced by the commands in your <TT>at</TT> job is automatically mailed to you.</P>

<P>To see which jobs you scheduled with <TT>at</TT>, enter <TT><B>at -l</B></TT>. Working with the preceding examples, you see the following results:</P>

<!-- CODE SNIP //-->

<PRE>

job 756603300.a at Sat Dec 21 01:23:00 1996

job 756604200.a at Fri Jan 24 17:00:00 1997

</PRE>

<!-- END CODE SNIP //-->

<P>Only your <TT>at</TT> jobs are listed.</P>

<P>To remove a scheduled <TT>at</TT> job, enter <TT><B>at -d</B></TT> followed by the job number. To remove the second job just listed, for example, enter this command:</P>

<!-- CODE SNIP //-->

<PRE>

<B>at -d 756604200.a</B>

</PRE>

<!-- END CODE SNIP //-->

<P>Table 19.3 summarizes the different ways to use the <TT>at</TT> command.</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 19.3</B> Summary of <TT>at</TT> Commands

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH WIDTH="30%" ALIGN="LEFT">Format

<TH WIDTH="70%" ALIGN="LEFT">Action

<TR>

<TD COLSPAN="2"><HR>

<TR>

<TD VALIGN="TOP"><TT>at <I>hh:mm</I></TT>

<TD>Schedules job at the hour (<I>hh</I>) and minute (<I>mm</I>) specified, using a 24-hour clock

<TR>

<TD VALIGN="TOP"><TT>at <I>hh:mm month day year</I></TT>

<TD>Schedules job at the hour (<I>hh</I>), minute (<I>mm</I>), month, day, and year specified

<TR>

<TD><TT>at -l</TT>

<TD>Lists scheduled jobs; an alias for the <TT>atq</TT> command

<TR>

<TD VALIGN="TOP"><TT>at now &#43;<I>count time-units</I></TT>

<TD>Schedules the job right now plus <I>count</I> number of <I>time-units</I>; time units can be minutes, hours, days, or weeks

<TR>

<TD VALIGN="TOP"><TT>at -d <I>job_id</I></TT>

<TD>Cancels the job with the job number matching <I>job_id</I>; an alias for the <TT>atrm</TT> command

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<P>As the root user, you can use any of these commands; for other users, the files /etc/at.allow and /etc/at.deny determine the permission to use the commands. If /etc/at.allow exists, only the user names listed in the file are allowed to use the <TT>at</TT> command. If the /etc/at.allow file doesn&#146;t exist, the system checks /etc/at.deny, and every user name not mentioned in /etc/at.deny is allowed to use <TT>at</TT> (in other words, any user listed in /etc/at.deny isn&#146;t allowed to use <TT>at</TT>). If neither file exists, only the superuser (root) can use <TT>at</TT>. If /etc/at.deny is empty, every user can use <TT>at</TT>.</P>

<H4 ALIGN="LEFT"><A NAME="Heading9"></A><FONT COLOR="#000077">Running Long Tasks with <I>batch</I>

</FONT></H4>

<P>Linux has more than one command for scheduling tasks. The preceding section describes the <TT>at</TT> command, which gives you the power to dictate when a task will run. However, it&#146;s always possible that the system can be loaded down with more jobs scheduled at one time than it can comfortably handle. The <TT>batch</TT> command lets the operating system decide an appropriate time to run a process. When you schedule a job with <TT>batch</TT>, Linux starts and works on the process whenever the system load isn&#146;t too great. Jobs run under <TT>batch</TT> execute in the background, just as those run with <TT>at</TT>. In fact, <TT>batch</TT> is an alias for <TT>at -b</TT> in Red Hat Linux.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>TIP:&nbsp;&nbsp;</B>It&#146;s useful to put commands you want to run with <TT>at</TT> or <TT>batch</TT> in a file so that you don&#146;t have to retype the commands each time you want to run the jobs. To use <TT>batch</TT> to schedule the commands in the file getdone, enter the command <TT><B>batch &lt; getdone</B></TT>.<HR></FONT>

</BLOCKQUOTE>

<P>The format for <TT>batch</TT> commands is to enter the list of commands on the lines following the <TT>batch</TT> command; you terminate the list of commands with &lt;Ctrl-d&gt;. You can put the list of commands in a file and then redirect the input of the file to <TT>batch</TT>. To sort a collection of files, print the results, and notify the user named boss that the job is done, enter the following commands:</P>

<!-- CODE SNIP //-->

<PRE>

<B>batch</B>

<B>sort /usr/sales/reports/* | lp</B>

<B>echo &#147;Files printed, Boss!&#148; | mailx -s&#147;Job done&#148; boss</B>

</PRE>

<!-- END CODE SNIP //-->

<P>The system returns the following response:

</P>

<!-- CODE SNIP //-->

<PRE>

job 7789001234.b at Fri Feb 21 11:43:09 1997

</PRE>

<!-- END CODE SNIP //-->

<P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="384-386.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="388-390.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 + -