📄 770-772.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Unleashed, Third Edition:cron and at</TITLE>
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0672313723//-->
<!--TITLE=Linux Unleashed, Third Edition//-->
<!--AUTHOR=Tim Parker//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Sams//-->
<!--CHAPTER=46//-->
<!--PAGES=770-772//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="769-770.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch47/773-778.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>There are more variations possible, but you can see the syntax. If you want the command to execute on Friday, issue the command in one of these formats:
</P>
<!-- CODE SNIP //-->
<PRE>
at 8:30 pm Friday < reorg.data
at 20:30 Fir < reorg.data
</PRE>
<!-- END CODE SNIP //-->
<P>Some versions of <TT>at</TT> are even more talented and handle special words. For example, this command will execute the commands next week on Monday:</P>
<!-- CODE SNIP //-->
<PRE>
at 0900 Monday next week < reorg.data
</PRE>
<!-- END CODE SNIP //-->
<P>Not all versions of <TT>at</TT> can handle these complex formats.</P>
<P>When you submit a program to <TT>at</TT> for execution, you receive a job ID number. The job ID uniquely identifies the <TT>at</TT> command you just issued. For example, look at the output from this <TT>at</TT> command:</P>
<!-- CODE SNIP //-->
<PRE>
$ at 6 < do_it
job 827362.a at Wed Aug 31 06:00:00 EDT 1995
</PRE>
<!-- END CODE SNIP //-->
<P>In this case, the job ID is <TT>827362.a</TT> and the ID is needed to make any changes to the job.</P>
<P>You can list all the jobs you have queued with <TT>at</TT> using the <TT>-l</TT> (list) option. The output usually tells you when the command is set to execute, but not what the command is:</P>
<!-- CODE SNIP //-->
<PRE>
$ at -l
user = tparker job 827362.a at Wed Aug 31 06:00:00 EDT 1995
user = tparker job 829283.a at Wed Aug 31 09:30:00 EDT 1995
</PRE>
<!-- END CODE SNIP //-->
<P>Some versions of Linux may support the shorter form of the command with <TT>atq</TT> (display the <TT>at</TT> queue). If you get an error message when you issue the <TT>atq</TT> command, you have to use the <TT>at -l</TT> format.</P>
<P>To remove an <TT>at</TT> job from the system, you need the job ID and the <TT>at -r</TT> (remove) command. For example, the following command removes the specified job:</P>
<!-- CODE SNIP //-->
<PRE>
at -r 2892732.a
</PRE>
<!-- END CODE SNIP //-->
<P>Linux does not return a message to indicate the job has been canceled, but if you list the queue, you see the job is gone. You can only remove your own jobs (except for <TT>root</TT>, which can remove any). Some Linux versions support the <TT>atrm</TT> command as well as the <TT>-r</TT> option.</P>
<P>All jobs that are queued into <TT>at</TT> are kept in the directory <TT>/usr/spool/cron/atjobs</TT> with the job ID number as the file name. As with <TT>cron</TT>, there is an <TT>at.allow</TT> and <TT>at.deny</TT> file in either <TT>/usr/lib/cron</TT> or <TT>/etc/cron.d</TT> directories to control who can and can’t use <TT>at</TT>. As with <TT>cron</TT>, if you want all users on your system to be able to use <TT>at</TT>, create an empty <TT>cron.deny</TT> file.</P>
<P>When an <TT>at</TT> job is executed, all output (standard output and error messages) are mailed back to the username who submitted the job unless they have been redirected. The <TT>at</TT> command retains all the environment variables and directory settings of the user. If you look at a queued job in <TT>/usr/spool/cron/atjobs,</TT> you will see all the variables defined prior to the command about to be executed.</P>
<H3><A NAME="Heading7"></A><FONT COLOR="#000077">Summary</FONT></H3>
<P>As you have seen, <TT>cron</TT> and <TT>at</TT> are quite easy to use. They are also a system administrator’s best friend because you can automate tiresome tasks like database cleanups, disk space checking, flushing log files, and tape backups with <TT>cron</TT> or <TT>at</TT>. While <TT>cron</TT> and <TT>at</TT> can’t do everything for you, they can handle repetitive tasks with ease.</P>
<P>Most Linux systems have a number of sample <TT>cron</TT> files supplied with the operating system. Examine those files (or list the current <TT>crontab</TT> file while logged in as <TT>root</TT>) to see what the operating system wants to execute on a regular basis. Use those commands as the starting point and add your own commands. From here there are a number of chapters you can turn to for related information:</P>
<DL>
<DD>Backing up your system is discussed in Chapter 45, “Backups.”
<DD>Setting up your Linux system to serve the Internet is discussed in Chapter 47, “Setting Up an Internet Site.”
<DD>Applications you can run under Linux are discussed in Chapter 62, “Adabas-D and Other Databases,” through Chapter 64, “Lone Star Software’s Lone-Tar.”
</DL>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="769-770.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch47/773-778.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 + -