Do you use expect? You should

expect is a tool built using Tcl which allows you to automate many tasks that would otherwise mean tedious repetition at the command line. While many tools come with a command line interface, they don’t lend themselves well to scripting — telnet is the classic example. But with expect you can script these tools as easily as bash.

How much do I need to know?

Just knowing a small set of expect keywords can increase your productivity enormously — and these keywords are reasonably intuitive to boot: spawn, expect, send, and interact.

That’s it. With these four keywords you can do so much. Want to get quick ssh access to a machine?

spawn ssh remote_host -l potoole
expect -exact "potoole@remote_host's password: "
send -- "the_password!r"
expect "*remote_host*"


This is where some real magic happens. autoexpect monitors an interactive session, and creates a matching expect script. It even has a Prompt mode, enabled with the -p flag, which tells autoexpect to only pay attention to the last line of the output — which is usually the prompt. This is really useful if some of the output varies from session to session.

Any time I find myself entering the same commands at an interactive prompt more than twice, I immediately start thinking about expect. And so should you.