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

📄 0271-0274.html

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




<HTML>

<HEAD>

<TITLE>Developer.com - Online Reference Library - 0672311623:SAMS TEACH YOURSELF LINUX IN 24 HOURS:Personal Productivity Tools</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=0672311623 //-->

<!-- TITLE=SAMS TEACH YOURSELF LINUX IN 24 HOURS //-->

<!-- AUTHOR=BILL BALL, STEPHEN SMOOGEN //-->

<!-- PUBLISHER=MACMILLAN //-->

<!-- IMPRINT=SAMS //-->

<!-- PUBLICATION DATE=1998 //-->

<!-- CHAPTER=18 //-->

<!-- PAGES=0271-0280 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->







<P><CENTER>

<a href="../ch17/0267-0270.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0275-0278.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-271"><P>Page 271</P></A>









<H3><A NAME="ch18_ 2">

Hour 18

</A></H3>



<H2>

<A NAME="ch18_ 3">

Personal Productivity Tools

</A>

</H2>





<P>This hour shows you some calendars, commands, and X11 clients you

can use to help your personal productivity. Whether it's keeping a diary

or creating reminders, you'll learn how to use these tools under Linux to

keep you on track and on schedule with your life.

</P>





<P>Each program or technique discussed in this hour can be accomplished

with software you'll find on the CD-ROM that came with your book.

After reading this discussion, you'll find additional ways to use these programs

to craft your own set of tools and techniques for personal productivity.

</P>

<A NAME="PAGENUM-272"><P>Page 272</P></A>





<H3><A NAME="ch18_ 4">

Scheduling Personal Reminders and Tasks with the

at Command

</A></H3>





<P>If you need to keep track of important schedules, set reminders, or run

programs unattended, you can use the at command. This command, found under the

/usr/bin directory, will schedule commands, or jobs, to be run at a time you specify. For

example, if you're working on a project but need to remember to catch your car pool, you can

enter a quick at job from the command line.

</P>





<TABLE BGCOLOR=#FFFF99><TR><TD>TIME SAVER</TD></TR><TR><TD>

<BLOCKQUOTE>

Your system should allow you to use the at commands by default. If it does

not, see Hour 24, &quot;Scheduling,&quot; on how to enable

at command facilities for your system.

</BLOCKQUOTE>

</TD></TR></TABLE>







<P>The following shows the at command for the car pool example:

</P>



<!-- CODE //-->

<PRE>

# at 16:15

xmessage -display :0.0 &quot;The car pool is leaving in 15 minutes.&quot;

EOT

Job 4 will be executed using /bin/sh

</PRE>

<!-- END CODE //-->





<P>This will tell the at command to run the

xmessage program to display the text of your

message about your car pool on the specified X11 display. The

-display command-line option will tell the

xmessage command which screen to show the message on, usually 0.0, which

you can find with

</P>





<!-- CODE SNIP //-->

<PRE>

# printenv | fgrep DISPLAY

</PRE>

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





<P>This command line searches a listing of your environment variables (discussed in

Hour 6, &quot;Using the Shell&quot;) and prints the value of the

DISPLAY variable. The end-of-text in the listing means that you should press Ctrl-D to close the command and then enter the

job. If you make a mistake in the syntax of the command, you'll receive a mail message

at the scheduled time.

</P>





<P>You can also use the at command to provide a visual reminder, if you're using X11,

by controlling the color of your desktop, for example:

</P>



<!-- CODE //-->

<PRE>

# at 16:15

xsetroot -display :0.0 -solid Red

xmessage -display :0.0 &quot;The car pool is leaving in 15 minutes.&quot;

EOT

Job 8 will be executed using /bin/sh

</PRE>

<!-- END CODE //-->







<A NAME="PAGENUM-273"><P>Page 273</P></A>







<P>

This will turn your desktop a solid red color at the appointed time, then display

your message. As you can see, you can combine multiple commands to do a number of

things at once. If you find this approach convenient, you can also type these commands

into a text file called carpool and run the commands with the following:

</P>



<!-- CODE SNIP //-->

<PRE>

# at 16:15 -f carpool

</PRE>

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





<P>As a further convenience, you can place this command line in your

.xintrc script in your home directory to schedule the job after you start X11 at the beginning of the day.

You can see a list of scheduled jobs with the atq command, for example:

</P>



<!-- CODE //-->

<PRE>

# atq

Date                    Owner   Queue   Job#

17:00:00 12/07/97       bball   c       15

18:00:00 12/07/97       bball   c       16

19:00:00 12/07/97       bball   c       17

16:00:00 12/25/97       bball   c       18

</PRE>

<!-- END CODE //-->





<P>This shows that three jobs are scheduled for December 7, with another scheduled

for December 25. When you schedule jobs with the

at command, a shell script containing your commands is created in the

/var/spool/at directory. The atq command looks in

this directory for your jobs, then prints them to your display.

</P>





<P>You can use the at command to schedule a job minutes, hours, days, weeks, or even

years in advance. If you want to run your carpool reminder file in three hours, you can use

the at command's plus sign (+) command-line option, for example:

</P>





<!-- CODE SNIP //-->

<PRE>

# at +3 hours -f carpool

</PRE>

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





<P>This would run your job three hours from the current system time. If

you want to remove one or two jobs, you can use the

atrm command. For example, using your job queue

from the earlier example, you would type

</P>





<!-- CODE SNIP //-->

<PRE>

# atrm 16 18

</PRE>

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





<P>This would remove jobs 16 and 18, but leave the other two intact. Using the

at command is a handy way to program one-time reminders for specific times. In the next

section, I'll show you how to schedule other jobs to run at regular intervals.

</P>





<TABLE BGCOLOR=#FFFF99><TR><TD>JUST A MINUTE</TD></TR><TR><TD>

<BLOCKQUOTE>

You can also use Rob Nation's X11 client, rclock, to schedule

reminders or run programs at a selected day or time. To build a reminder, create a file called

.rclock in your home directory and enter reminder command lines&#151;for example:

11:30 mtwtf Time for lunch!

</P>

<P>This displays a reminder for lunch during the week.<BR>

</BLOCKQUOTE>

</TD></TR></TABLE>







<A NAME="PAGENUM-274"><P>Page 274</P></A>











<H3><A NAME="ch18_ 5">

Scheduling Regular Reminders with the crontab Command

</A></H3>





<P>Although the at command is helpful for scheduling one-time jobs, you'll want to use

Paul Vixie's crontab command if you need regular tasks completed at regular intervals. The

crontab command, found under the /usr/bin directory, is used to enter your desired times

and commands into a personal file.

</P>





<P>The crontab command works by looking for

crontab schedules, by username, in the

/var/spool/cron directory. The crontab file for your Linux system is called

crontab and is located in the /etc directory. The program that runs the system and user

cron schedules is the cron daemon, which is started when you boot Linux, and which wakes up each minute to check

the system and user files.

</P>





<P>To create your own crontab file, you must use the command's

-e option, for example:

</P>





<!-- CODE SNIP //-->

<PRE>

# crontab -e

</PRE>

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





<TABLE BGCOLOR=#FFFF99><TR><TD>TIME SAVER</TD></TR><TR><TD>

<BLOCKQUOTE>

Make sure you've enabled crontab use for your system. See Hour 24 for

details on how to do this. You'll also want to define the default

EDITOR environment variable to your favorite text editor when you create or edit your

crontab files. See Hour 6 for information on how to set environment variables.

</BLOCKQUOTE>

</TD></TR></TABLE>







<P>This command will launch the default text editor, defined in your shell's

EDITOR environment variable, so you can create or edit your personal

crontab file. If your default editor is vi, and you either don't want to use vi, or would like to use a different

editor, you can temporarily change the $EDITOR variable using your shell. For example, if

you're using the bash shell, and want to use the pico text editor, you can use

</P>





<!-- CODE SNIP //-->

<PRE>

# EDITOR /usr/bin/pico; export EDITOR

</PRE>

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





<P>This will set the default editor to the pico editor. You can confirm this by searching

your environment variables, for example:

</P>



<!-- CODE SNIP //-->

<PRE>

# printenv | fgrep EDITOR

EDITOR=/usr/bin/pico

</PRE>

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





<P>Whichever editor you use, you'll initially be presented an empty file if you've

never created a crontab file. You can then enter crontab settings. Before you can enter your own schedule, you should know how to format a

crontab request. You'll find the format of crontab requests and some sample entries in the crontab manual page under the /usr/man/man5 

</P>

<P><CENTER>

<a href="../ch17/0267-0270.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0275-0278.html">Next</A>

</CENTER></P>















</td>
</tr>
</table>

<!-- begin footer information -->









</body></html>

⌨️ 快捷键说明

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