📄 0450-0452.html
字号:
<HTML>
<HEAD>
<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:Automating Tasks</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=0672311739 //-->
<!-- TITLE=RED HAT LINUX 2ND EDITION //-->
<!-- AUTHOR=DAVID PITTS ET AL //-->
<!-- PUBLISHER=MACMILLAN //-->
<!-- IMPRINT=SAMS PUBLISHING //-->
<!-- PUBLICATION DATE=1998 //-->
<!-- CHAPTER=22 //-->
<!-- PAGES=0437-0454 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0447-0449.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0453-0454.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-450"><P>Page 450</P></A>
<H5><A NAME="ch22_ 25">
Python
</A></H5>
<P>Python can be of special interest to Red Hat Linux users. Python is object-oriented,
modern, clean, portable, and particularly easy to maintain. If you are a full-time system
administrator looking for a scripting language that will grow with you, consider Python. The official
home page for Python is <a href="http://www.python.org.">http://www.python.org.</A>
</P>
<H5><A NAME="ch22_ 26">
Emacs
</A></H5>
<P>Emacs is one of the most polarizing lightning rods for religious controversy among
computer users. Emacs has many intelligent and zealous users who believe it the ideal platform for
all automation efforts. Its devotees have developed what was originally a screen editor into a
tool with capabilities to manage newsgroup discussion, Web browsing, application
development, general-purpose scripting, and much more. For the purposes of this chapter, what you need
to know about Emacs is as follows:
</P>
<UL>
<LI> It's an editor that you ought to try at some point in your career.
<p><LI> If you favor integrated development environments, Emacs can do almost anything
you imagine. As an editor, it emulates any other editor, and its developers ensure that
it always offers state-of-the-art capabilities in language-directed formatting,
application integration, and development automation.
</UL>
<P>Even if the "weight" of Emacs (it's slow on startup and seems to require quite a bit of
education and configuration) sways you against its daily use, keep it in mind as a paragon of
how sophisticated programming makes common operations more efficient.
</P>
<H5><A NAME="ch22_ 27">
procmail
</A></H5>
<P>Computer use has exploded in the Internet era. The most indispensable, most used
Internet function is e-mail. Can e-mail be automated?
</P>
<P>Yes, of course, and it's perhaps the single best return on your invested time to do so.
Along with aliases, distribution lists, startup configurations, and the plethora of mail agents or
clients with their feature sets, you'll want to learn about
procmail. Suppose that you receive a hundred messages a day, that a fifth of them can be handled completely automatically, and that
it takes at least three seconds of your time to process a single piece of e-mail; those are
conservative estimates, from the experience of the computer workers I know. A bit of
procmail automation will save you at least a minute a day, or six hours a year. Even conservative estimates
make it clear that an hour of setting up procmail pays for itself many times over.
</P>
<P>Along with the man procmail* pages, serious study of
procmail starts with the page
<a href="http://www.faqs.org/faqs/mail/filtering-faq">http://www.faqs.org/faqs/mail/filtering-faq</A>, Nancy McGough's "Filtering Mail FAQ." This
gives detailed installation and debugging directions. To supplement it, I've launched the page
<a href="http://starbase.neosoft.com/~claird/comp.mail.misc/procmail.html">http://starbase.neosoft.com/~claird/comp.mail.misc/procmail.html</A>
to keep you updated
</P>
<A NAME="PAGENUM-451"><P>Page 451</P></A>
<P>on the latest procmail news. Because your Red Hat Linux machine will almost certainly
have a correctly configured procmail, you can immediately begin to program your personal use
of it. As a first experiment, create exactly these files:
~/.procmailrc, with contents
</P>
<!-- CODE //-->
<PRE>
VERBOSE=on
MAILDIR=$HOME/mail
PMDIR=$HOME/.procmail
LOGFILE=$PMDIR/log
INCLUDERC=$PMDIR/rc.testing
~/.procmail/rc.testing, holding
:0:
* ^Subject:.*HOT
SPAM.HOT
</PRE>
<!-- END CODE //-->
<P>and ~/.forward, with
</P>
<!-- CODE SNIP //-->
<PRE>
"|IFS=' ` && exec /usr/local/bin/procmail -f || exit 75 #YOUR_EMAIL_NAME"
</PRE>
<!-- END CODE SNIP //-->
<P>After you create these three, set necessary permissions with the following:
</P>
<!-- CODE SNIP //-->
<PRE>
chmod 644 ~/.forward
chmod a+x ~/.
</PRE>
<!-- END CODE SNIP //-->
<P>Now exercise your filter with the following:
</P>
<!-- CODE //-->
<PRE>
echo "This is the first message." | mail -s "Example of HOT SPAM." YOUR_EMAIL_NAME
echo "This is the second message." | mail -s "Desired message." YOUR_EMAIL_NAME
</PRE>
<!-- END CODE //-->
<P>What you now see in your mailbox is only one new item, the one with the subject
Desired message. You also have a new file in your home directory,
SPAM.HOT, holding ... the first message.
</P>
<P>procmail is a robust, flexible utility you can program to achieve even more useful
automations than this. When you gain familiarity with it, it will become natural to construct rules that,
for example, automatically discard obvious spam, sort incoming mailing-list traffic, and
perhaps even implement pager forwarding, remote system monitoring, or FAQ response. This can
save you considerable time each day.
</P>
<H5><A NAME="ch22_ 28">
calendar
</A></H5>
<P>calendar is quite specialized, easy to use, and, because it matches a real-world need
particularly well, very useful. calendar takes responsibility for
sending messages to your screen to remind you of events or responsibilities. You can download
calendar from ftp://ftp.redhat.com/pub/contrib/i386, file
calendar-8.4-3.i386.rpm. Experiment with calendar by creating a local
file called calendar (the command and the specification file have the same name, in general)
with the following contents:
</P>
<!-- CODE SNIP //-->
<PRE>
#include "/usr/lib/gcal-lib/calendar.holid"
Monday\tTake out trash.
</PRE>
<!-- END CODE SNIP //-->
<A NAME="PAGENUM-452"><P>Page 452</P></A>
<!-- CODE //-->
<PRE>
Tuesday\tFeed dolphin.
Wednesday\tRe-synchronize orgone collector.
Thursday\tKaryotype produce from refrigerator.
Friday\tTake out trash.
Saturday\tPractice polo.
Sunday\tClimb Matterhorn.
</PRE>
<!-- END CODE //-->
<P>Run calendar. You'll see a few historical events with current anniversaries, and your own
applicable daily chores. Three aspects of calendar give it dramatic power:
</P>
<UL>
<LI> You can run
calendar automatically, using the techniques you've learned so far:
For example, have cron put a reminder in your e-mail every morning or invoke
calendar from your shell's startup file so that it's run each time you log in.
<LI>
calendar has a sophisticated knowledge of calendars. It will, on request, remind
you when it's the second Tuesday of the month, the day after Easter, or Mother's Day.
See man calendar for details.
<LI> The
#include mechanism permits information-sharing. If your
calendar begins
</UL>
<!-- CODE //-->
<PRE>
#include "/some/centrally/maintained/directory/calendar.bigboss"
#include "/some/centrally/maintained/directory/calendar.cafetaria"
/* My own stuff follows ... */
</PRE>
<!-- END CODE //-->
<P> the first reminders calendar gives you will be those for the company president and
the lunch-time menu, with your personal events after.
</P>
<P>Although calendar does a small job, it does it efficiently. Consider whether its capability
to focus attention on the upcoming days' priorities matches your needs.
</P>
<H4><A NAME="ch22_ 29">
Internal Scripts
</A></H4>
<P>One more element of the automation attitude is to be on the lookout for opportunities
within every application you use. Scripting has become a pervasive theme, and almost all
common applications have at least a rudimentary macro or scripting capability. IRC users know
about bots, Web browsers typically expose at least a couple of scripting interfaces, all modern
PPP clients are scriptable, and even such venerable tools as
vi and ftp have configuration, shortcut, and macro capabilities that enormously magnify productivity. If you use a tool regularly,
take a few minutes to reread its presentation in this volume; chances are, you'll come up with a
way to make your work easier and more effective.
</P>
<H3><A NAME="ch22_ 30">
Concluding Challenge for an Automater—Explaining Value
</A></H3>
<P>You've become knowledgeable and experienced in scripting your computer so that it best
serves you. You know how to improve your skills in script-writing. You've practiced different
approaches enough to know how to solve problems efficiently. The final challenge in your
automation career is this: How do you explain how good you have become?
</P>
<P><CENTER>
<a href="0447-0449.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0453-0454.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -