14.06.2014 Views

Unix Power Tools

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

28.18<br />

Expect comes with several example scripts that demonstrate how you can do<br />

many things that are impossible with traditional shells. For example, the<br />

passmass script lets you update your password on many unrelated machines<br />

simultaneously. The rftp script provides your regular ftp client with additional<br />

commands to do recursive FTP in either direction. The cryptdir script encrypts<br />

all the files in a directory. And an amusing script is provided that lets two chess<br />

processes play each other. Expect has no limit to the number of interactive programs<br />

it can drive at the same time. The <strong>Unix</strong> system may limit Expect, though,<br />

by controlling the maximum number of processes or other system resources<br />

available.<br />

Testing: A Story<br />

Many people use Expect for testing. You can test interactive programs as easily<br />

as you can automate them. And hardware lends itself to testing with Expect, too.<br />

For example, we solved a thorny problem when we had to deal with an unreliable<br />

bank of modems. We were receiving dozens of calls each week reporting<br />

“the modem is hung.” No indication of which modem, of course. And it was<br />

always too late for us to ask the user to try something to investigate the problem.<br />

The connection was gone by then. Our solution was an Expect script that<br />

connected to each modem hourly and exercised it. Any problems were recorded<br />

so that we had a clear and full history of each modem’s behavior. As soon as a<br />

defective or hung modem was encountered, the Expect script would send email<br />

to the system administrator. With this script in place, reports of modem problems<br />

from our users dropped to zero.<br />

Other Problems<br />

These are just a few of the problems that can be solved with Expect. And as with<br />

all Expect solutions, recompilation of the original programs is unnecessary. You<br />

don’t even need the source code! Expect handles many other problems as well.<br />

For example, Expect can wrap existing interactive tools with GUI wrappers. This<br />

means you can wrap interactive programs with graphic frontends to control<br />

applications by buttons, scrollbars, and other graphic elements. And Expect<br />

scripts work great as CGI scripts or from cron (25.2) or inetd [the daemon that<br />

controls Internet services provided by a system—JP]. Finally, learning Expect<br />

may be easier than you think. Expect can watch you interact and then produce<br />

an Expect script for you. Interaction automation can’t get much easier than this!<br />

More information on Expect is available in ExploringExpect, by Don Libes, from<br />

O’Reilly & Associates.<br />

—DL<br />

570 Part VI: Scripting<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2009 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!