The CHAT script defines the dialog that occurs between the client and the server during the connection phase. A simple non-interactive CHAT script uses send and expect keywords to specify the character strings exchanged, as shown in the following example:
# # Chat script for ppp login # # # Set the line regarding the remote site configuration # Due to UUCP limitations some systems only accept cs7 # # setline cs7 parodd send RETURN expect "ogin:" 10 onerror send BREAK repeat 3 send "ppp1" expect "word: " 40 # # Set the ppp password of the remote host here # send "okppp1" |
When it initiates the call, the client waits for a response from the remote server to begin the login sequence. The length of time the client waits, and the number of times it attempts to initiate the call, are defined by the following entry:
expect "ogin:" 10 onerror send BREAK repeat 3 |
The expected response is ogin. The first figure (10) defines the wait period, and the second figure (3) defines the number of call initiation attempts. You can modify both of these parameters.
For example, to retry the call initiation once every 5 seconds for a total of 10 attempts, change the line in the file to:
expect "ogin:" 5 onerror send BREAK repeat 10 |
Interactive CHAT scripts use echo and read keywords to display prompts and to acquire user input. The user input is stored as variables, which are identified by the $ prefix. For example, an interactive version of the previous script could be:
send RETURN expect "ogin:" 10 onerror send BREAK repeat 3 echo "Enter your PPP login id: " read $login send "$login" expect "word: " 40 echo "Enter your PPP password: " read $password send "$password" |
A more complex example shows a CHAT script used to manage the interaction between the user and a dynamic challenge-response authentication system:
send RETURN expect "ID:" 10 onerror send BREAK repeat 3 echo "Enter your user ID number: " read $id send "$id" expect "Challenge: ${challenge,6}" 10 echo "Enter the response for Challenge ${challenge}: " read $response send "$response" expect "${host}:" 20 echo "Connected to ${host}\n" send "ppp" |
In this example, the script reads a user id and sends it to the server. It waits for 10 seconds for a response from the server that starts with the string Challenge: and then reads the next six characters which represent the challenge value.
The script then displays the challenge value, waits for the user to enter the corresponding response, and sends this to the server. If the response is accepted, the connection is completed.
The {} brackets are used to delimit a variable when it appears with other characters as part of a character string.