The chat script defines the communications.
A script consists of one or more "expect-send" pairs of strings,
separated by spaces, with an optional "subexpect-subsend" string
pair, separated by a dash as in the following example:
ogin:-BREAK-ogin: ppp ssword: hello2u2
This line indicates that the chat program should expect the
string "ogin:". If it fails to receive a login prompt within the
time interval allotted, it is to send a break sequence to the
remote and then expect the string "ogin:". If the first "ogin:"
is received then the break sequence is not generated.
Once it received the login prompt the chat program will send the
string ppp and then expect the prompt "ssword:". When it receives
the prompt for the password, it will send the password hello2u2.
A carriage return is normally sent following the reply string. It
is not expected in the "expect" string unless it is specifically
requested by using the \r character sequence.
The expect sequence should contain only what is needed to
identify the string. Since it is normally stored on a disk file,
it should not contain variable information. It is generally not
acceptable to look for time strings, network identification
strings, or other variable pieces of data as an expect string.
To help correct for characters which may be corrupted during the
initial sequence, look for the string "ogin:" rather than
"login:". It is possible that the leading "l" character may be
received in error and you may never find the string even though
it was sent by the system. For this reason, scripts look for
"ogin:" rather than "login:" and "ssword:" rather than
"password:".
A very simple script might look like this:
ogin: ppp ssword: hello2u2
In other words, expect ....ogin:, send ppp, expect ...ssword:,
send hello2u2.
In actual practice, simple scripts are rare. At the vary least,
you should include sub-expect sequences should the original
string not be received. For example, consider the following
script:
ogin:--ogin: ppp ssword: hello2u2
This would be a better script than the simple one used earlier.
This would look for the same login: prompt, however, if one was
not received, a single return sequence is sent and then it will
look for login: again. Should line noise obscure the first login
prompt then sending the empty line will usually generate a login
prompt again.