📄 439-442.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=439-442//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="437-439.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch27/443-446.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading10"></A><FONT COLOR="#000077">Enabling <I>at</I> Command Service
</FONT></H4>
<P>The <TT>at</TT> command service (as well as the <TT>batch</TT> command service) reads commands from standard input or a specified file that is to be executed at a later time via <TT>/bin/sh</TT>. The syntax for the <TT>at</TT> command is as follows:</P>
<!-- CODE SNIP //-->
<PRE>
<B>at</B> [-<B>V</B>] [-<B>q</B> <I>queue</I>] [<B>-f</B> <I>file</I>] [<B>-mldbv</B>]
<B>TIME</B>
<B>at -c</B> <I>job</I> [<I>job</I>...]
<B>atq</B> [<B>-V</B>] [<B>-q</B> <I>queue</I>] [-v]
<B>atrm</B> [<B>-V</B>] <I>job</I> [<I>job</I>...]
<B>batch</B> [<B>-V</B>] [<B>-q</B> <I>queue</I>] [-f <I>file</I>] [<B>-mv</B>] [<I>TIME</I>]
</PRE>
<!-- END CODE SNIP //-->
<P>Table 26.4 briefly describes what each command does.
</P>
<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 26.4</B> The <I>at</I> commands</B>
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TH WIDTH="20%" ALIGN="LEFT">Command
<TH WIDTH="80%" ALIGN="LEFT">Description
<TR>
<TD><TT>at</TT>
<TD>Executes commands at a specified time
<TR>
<TD VALIGN="TOP"><TT>atq</TT>
<TD>Lists the user’s pending jobs (unless the user is the superuser, in which case it lists everyone’s pending jobs)
<TR>
<TD><TT>atrm</TT>
<TD>Removes at jobs
<TR>
<TD><TT>batch</TT>
<TD>Executes commands when system load levels permit
<TR>
<TD COLSPAN="2"><HR>
</TABLE>
<P>Options for the <TT>at</TT> command include the following:</P>
<DL>
<DD><B>•</B> <TT>-b</TT> An alias for batch.
<DD><B>•</B> <TT>-c</TT> Shows jobs listed on the command line to standard output (the monitor).
<DD><B>•</B> <TT>-d</TT> An alias for <TT>atrm</TT>.
<DD><B>•</B> <TT>-f</TT> Reads the job from a file rather than standard input.
<DD><B>•</B> <TT>-l</TT> An alias for <TT>at</TT>.
<DD><B>•</B> <TT>-m</TT> Mails the user when the job is complete. This sends mail to the user specified (even if there is no output).
<DD><B>•</B> <TT>-q</TT> Uses a specified queue. A queue designation consists of a single letter, with <TT>c</TT> being the default for <TT>at</TT>, and <TT>E</TT> for <TT>batch</TT>. Valid designations are <TT>a..z</TT> and <TT>A..Z</TT>. Queues with letters closer to <TT>Z</TT> (<TT>A</TT> is closer to <TT>Z</TT> than <TT>z</TT> is) run with increased performance. If a job is submitted to a queue with an uppercase designation, the job is treated as a batch job. If <TT>atq</TT> is given a specific value, it shows jobs pending for only the specified queue.
<DD><B>•</B> <TT>-v</TT> Shows jobs that are complete, but not yet deleted.
<DD><B>•</B> <TT>-V</TT> Prints the version number to standard output.
</DL>
<P><FONT SIZE="+1"><B>Common Problems with the <I>at</I> Command
</B></FONT></P>
<P>Several people have had problems with <TT>at</TT> jobs, some to the point where they would prefer to make the job a <TT>cron</TT> job, and then go back after the fact and remove the <TT>cron</TT> job.</P>
<P>Most of the problems with <TT>at</TT> jobs are in defining them. A straight <TT>at</TT> job is simple enough if you are calling a single word for a command, but it can easily get confusing. For example, I tried to run the following simple at job:</P>
<!-- CODE SNIP //-->
<PRE>
at now + 2 minutes touch ~/touch_file
</PRE>
<!-- END CODE SNIP //-->
<P>When I pressed Enter, I got an error with the time:
</P>
<!-- CODE SNIP //-->
<PRE>
parse error. Last token seen: touch
Garbled Time.
</PRE>
<!-- END CODE SNIP //-->
<P>Using the <TT>echo</TT> command, you can turn this at job around, and thus avoid the problems with “garbled time.” Following is the same command, except I have turned it around with an <TT>echo</TT> command:</P>
<!-- CODE SNIP //-->
<PRE>
echo touch ~/touch_file | at now + 2 minutes
</PRE>
<!-- END CODE SNIP //-->
<P>Sure enough, this one worked without a problem, and two minutes later my file in my home directory (<TT>touch_file</TT>) had its access date set to the current time.</P>
<P>The same problem occurs when you try to configure a <TT>shutdown</TT> command to run at a specific time:</P>
<!-- CODE SNIP //-->
<PRE>
echo shutdown -fr now | at now + 4 hours
</PRE>
<!-- END CODE SNIP //-->
<P>This shuts down the system exactly four hours after this <TT>at</TT> job is initiated.</P>
<P><TT>at</TT> jobs can accept the standard <TT>hh:mm</TT> time, but if the specified time has already passed, the system assumes that you mean that time tomorrow. You can use some common words with <TT>at</TT> jobs to specify time, including <TT>NOON</TT>, <TT>MIDNIGHT</TT>, <TT>TEATIME</TT> (4:00 p.m.), <TT>TODAY</TT>, <TT>TOMORROW</TT>, and <TT>NOW</TT>. The use of <TT>am</TT> and <TT>pm</TT> is also allowed. Days in the future can also be specified, and months can be designated with their three-letter abbreviations. For example, if you wanted to execute something at 4 a.m. two days from now, the command would look like this:</P>
<!-- CODE SNIP //-->
<PRE>
at 4am + 2 days
</PRE>
<!-- END CODE SNIP //-->
<P>To run a job at noon on my birthday (November 25th), you would use the following:
</P>
<!-- CODE SNIP //-->
<PRE>
at noon Nov 25
</PRE>
<!-- END CODE SNIP //-->
<P>Finally, to shut down the system at 1 a.m. tomorrow, you would use the following:
</P>
<!-- CODE SNIP //-->
<PRE>
echo shutdown -fr now | at 1am tomorrow
</PRE>
<!-- END CODE SNIP //-->
<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD><FONT SIZE="+1"><B>Determining who can use the at command</B></FONT>
<BR>Root can always use the <TT><B>at</B></TT> command. All others depend upon the <TT><B>at.allow</B></TT> and the <TT><B>at.deny</B></TT> files.</TABLE>
<H4 ALIGN="LEFT"><A NAME="Heading11"></A><FONT COLOR="#000077">Allowing and Preventing Access to the <I>at</I> Command Service
</FONT></H4>
<P>By default, an empty <TT>/etc/at.deny</TT> file exists. Because it is empty, every user is allowed to use the <TT>at</TT> command. If there are user-names (as defined in the <TT>/etc/passwd</TT> file) in this file, then those users are <I>not</I> allowed to use the <TT>at</TT> command.</P>
<P>By default, <TT>/etc/at.allow</TT> does not exist. If it does exist, only users whose usernames are entered in this file can use the <TT>at</TT> command. This means that <TT>/etc/at.allow</TT> has precedence over <TT>/etc/at.deny</TT>. If both exist, only the <TT>/etc/at.allow</TT> file is checked, and only those entries are allowed to use the <TT>at</TT> command. If neither file exists, then only root can run <TT>at</TT> commands.</P>
<P>If a user attempts to run the <TT>at</TT> command, but his or her user name appears in the <TT>/etc</TT>/at.deny file (or an <TT>/etc/at.allow</TT> file exists and his or her username is not one of the entries), the following error occurs:</P>
<!-- CODE SNIP //-->
<PRE>
You do not have permission to use at.
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="437-439.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch27/443-446.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 + -