Web linux-server.50webs.com

Linux Server Basics

Chat Scripts:

A chat script defines the steps that are necessary to successfully connect to a remote server. The script is a list of expect/send pairs. Each pair consists of a string that the local system expects to receive, separated by whitespace from the response that it will send when the expected string is received. A sample script might contain the following:


$ cat dial-server
' ' ATZ
OK ATDT301-555-1234
CONNECT \d\d\r
gin: sophie
ord: TOga!toGA


The script in the previous listing contains instructions for the modem as well as the login for the remote server. The first line, expects nothing, which is what the empty string (' ') means, and sends a reset command to the modem. (ATZ is the standard Hayes reset command.) Next, the script expects the modem to send the string OK, and it responds with a Hayes dial command (ATDT). When the sample modem successfully connects to the remote modem, it displays the message CONNECT. In response to this, the script waits two seconds (\d\d) and then sends a carriage-return (\r).

Most systems don't really require anything like this, but it provides an example of a chat escape sequence. chat provides several escape sequences that can be used in the expect string or the response string. The table below lists these sequences and their meanings.

Escape Sequence Meaning
\b The backspace character
\c Don't send a terminating carriage-return; used at the end of a send string
\d Delay for one second
\K A line break
\n A newline character
\N An ASCII null character
\p Pause for 1/10 of a second
\q Send the string, but don't record it in the log; used at the end of a send string
\r A carriage-return
\s The space character
\t The tab character
\\ The backslash
\ddd The ASCII character with the octal value ddd (for example, \177 is the DEL character)
^character A control character (for example, ^G is a Ctrl+G)

The last two lines of the sample script are the remote login. The script expects gin:, which are the last four characters of the login: prompt, and responds with the username sophie. Next, ord:, which are the last four characters of the Password: prompt is expected, and TOga!toGA is sent as a response. Once the login is complete, the remote server runs the ppplogin script, and the PPP connection is up and running.

Note:
Chat is a very elementary scripting language. It is popular for setting up PPP connections because most PPP connections do not require a complex script. If yours does, you may need to use a more powerful scripting language. Linux provides both dip and expect. To read more about dip, see TCP/IP Network Administration, by Craig Hunt (O'Reilly, 2002). To read more about expect, see Exploring Expect, by Don Libes (O'Reilly, 1997).

.