Previous section   Next section

A.2 Expect

Expect is another scripting language that helps solve a different type of problem. Where Perl's strength is in pattern matching, Expect provides a way to automate interactive applications. We usually use Expect to imitate user sessions on a router to automate command-line tasks.

The Expect program is able to send one or more lines of output (such as router commands) and capture the results. It can also react to whatever the router sends it in return. This could be as simple as sending a user ID and waiting for the password prompt, or you could use this feature to check for various error conditions and react appropriately.

We often write scripts in Expect to automate boring, repetitive tasks. Computers are good at these tasks; people aren't. People make typos and get bored, or blink and miss key pieces of information. Also, because Expect can react immediately to the router's responses, the script can generally execute a series of commands very quickly. We think it's better to spend our time doing something productive while the computer is logging into all of our routers to do show commands. Expect lets us do this.

Expect is free to download, distribute, and use for any purpose. There are both Unix and Windows versions, and there are even companies doing commercial support for Expect. We wrote and tested all of the scripts in this book using Expect Version 5.31.2 on a Unix platform.

You can download Expect from the official web page at http://expect.nist.gov/. This site also has useful documentation and example scripts. For more information, we highly recommend Exploring Expect, by Don Libes (O'Reilly).


  Previous section   Next section
Top