Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training,
learning paths, books, tutorials, and more.

The log_user Command

In Expect scripts, it is very useful to hide the underlying dialogue, perhaps substituting new output. Sometimes it is useful just to show parts of the dialogue. You can do this with the log_user command. "log_user 0" stops the output of the spawned process from appearing in the standard output of Expect. "log_user 1" restores it.

The following script verifies email destinations at remote hosts by exercising the vrfy command supported by SMTP, a mail transfer protocol commonly used on the Internet. The script takes an email address as an argument.

The first command in the script extracts the user and host names from the original argument. This is done using the very same regexp command that I used as an example in Chapter 6 (p. 135). The remainder of the script performs the interaction with the remote host.