1CHAT(8) System Manager's Manual CHAT(8)
2
3
4
6 chat - Automated conversational script with a modem
7
9 chat [ options ] script
10
12 The chat program defines a conversational exchange between the computer
13 and the modem. Its primary purpose is to establish the connection
14 between the Point-to-Point Protocol Daemon (pppd) and the remote's pppd
15 process.
16
18 -f <chat file>
19 Read the chat script from the chat file. The use of this option
20 is mutually exclusive with the chat script parameters. The user
21 must have read access to the file. Multiple lines are permitted
22 in the file. Space or horizontal tab characters should be used
23 to separate the strings.
24
25 -t <timeout>
26 Set the timeout for the expected string to be received. If the
27 string is not received within the time limit then the reply
28 string is not sent. An alternate reply may be sent or the script
29 will fail if there is no alternate reply string. A failed script
30 will cause the chat program to terminate with a non-zero error
31 code.
32
33 -r <report file>
34 Set the file for output of the report strings. If you use the
35 keyword REPORT, the resulting strings are written to this file.
36 If this option is not used and you still use REPORT keywords,
37 the stderr file is used for the report strings.
38
39 -e Start with the echo option turned on. Echoing may also be turned
40 on or off at specific points in the chat script by using the
41 ECHO keyword. When echoing is enabled, all output from the modem
42 is echoed to stderr.
43
44 -E Enables environment variable substituion within chat scripts
45 using the standard $xxx syntax.
46
47 -v Request that the chat script be executed in a verbose mode. The
48 chat program will then log the execution state of the chat
49 script as well as all text received from the modem and the out‐
50 put strings sent to the modem. The default is to log through
51 the SYSLOG; the logging method may be altered with the -S and -s
52 flags.
53
54 -V Request that the chat script be executed in a stderr verbose
55 mode. The chat program will then log all text received from the
56 modem and the output strings sent to the modem to the stderr
57 device. This device is usually the local console at the station
58 running the chat or pppd program.
59
60 -s Use stderr. All log messages from '-v' and all error messages
61 will be sent to stderr.
62
63 -S Do not use the SYSLOG. By default, error messages are sent to
64 the SYSLOG. The use of -S will prevent both log messages from
65 '-v' and error messages from being sent to the SYSLOG.
66
67 -T <phone number>
68 Pass in an arbitary string, usually a phone number, that will be
69 substituted for the \T substitution metacharacter in a send
70 string.
71
72 -U <phone number 2>
73 Pass in a second string, usually a phone number, that will be
74 substituted for the \U substitution metacharacter in a send
75 string. This is useful when dialing an ISDN terminal adapter
76 that requires two numbers.
77
78 script If the script is not specified in a file with the -f option then
79 the script is included as parameters to the chat program.
80
82 The chat script defines the communications.
83
84 A script consists of one or more "expect-send" pairs of strings, sepa‐
85 rated by spaces, with an optional "subexpect-subsend" string pair, sep‐
86 arated by a dash as in the following example:
87
88 ogin:-BREAK-ogin: ppp ssword: hello2u2
89
90 This line indicates that the chat program should expect the string
91 "ogin:". If it fails to receive a login prompt within the time interval
92 allotted, it is to send a break sequence to the remote and then expect
93 the string "ogin:". If the first "ogin:" is received then the break
94 sequence is not generated.
95
96 Once it received the login prompt the chat program will send the string
97 ppp and then expect the prompt "ssword:". When it receives the prompt
98 for the password, it will send the password hello2u2.
99
100 A carriage return is normally sent following the reply string. It is
101 not expected in the "expect" string unless it is specifically requested
102 by using the \r character sequence.
103
104 The expect sequence should contain only what is needed to identify the
105 string. Since it is normally stored on a disk file, it should not con‐
106 tain variable information. It is generally not acceptable to look for
107 time strings, network identification strings, or other variable pieces
108 of data as an expect string.
109
110 To help correct for characters which may be corrupted during the ini‐
111 tial sequence, look for the string "ogin:" rather than "login:". It is
112 possible that the leading "l" character may be received in error and
113 you may never find the string even though it was sent by the system.
114 For this reason, scripts look for "ogin:" rather than "login:" and
115 "ssword:" rather than "password:".
116
117 A very simple script might look like this:
118
119 ogin: ppp ssword: hello2u2
120
121 In other words, expect ....ogin:, send ppp, expect ...ssword:, send
122 hello2u2.
123
124 In actual practice, simple scripts are rare. At the vary least, you
125 should include sub-expect sequences should the original string not be
126 received. For example, consider the following script:
127
128 ogin:--ogin: ppp ssword: hello2u2
129
130 This would be a better script than the simple one used earlier. This
131 would look for the same login: prompt, however, if one was not
132 received, a single return sequence is sent and then it will look for
133 login: again. Should line noise obscure the first login prompt then
134 sending the empty line will usually generate a login prompt again.
135
137 Comments can be embedded in the chat script. A comment is a line which
138 starts with the # (hash) character in column 1. Such comment lines are
139 just ignored by the chat program. If a '#' character is to be expected
140 as the first character of the expect sequence, you should quote the
141 expect string. If you want to wait for a prompt that starts with a #
142 (hash) character, you would have to write something like this:
143
144 # Now wait for the prompt and send logout string
145 '# ' logout
146
148 If the string to send starts with an at sign (@), the rest of the
149 string is taken to be the name of a file to read to get the string to
150 send. If the last character of the data read is a newline, it is
151 removed. The file can be a named pipe (or fifo) instead of a regular
152 file. This provides a way for chat to communicate with another pro‐
153 gram, for example, a program to prompt the user and receive a password
154 typed in.
155
157 Many modems will report the status of the call as a string. These
158 strings may be CONNECTED or NO CARRIER or BUSY. It is often desirable
159 to terminate the script should the modem fail to connect to the remote.
160 The difficulty is that a script would not know exactly which modem
161 string it may receive. On one attempt, it may receive BUSY while the
162 next time it may receive NO CARRIER.
163
164 These "abort" strings may be specified in the script using the ABORT
165 sequence. It is written in the script as in the following example:
166
167 ABORT BUSY ABORT 'NO CARRIER' '' ATZ OK ATDT5551212 CONNECT
168
169 This sequence will expect nothing; and then send the string ATZ. The
170 expected response to this is the string OK. When it receives OK, the
171 string ATDT5551212 to dial the telephone. The expected string is CON‐
172 NECT. If the string CONNECT is received the remainder of the script is
173 executed. However, should the modem find a busy telephone, it will send
174 the string BUSY. This will cause the string to match the abort charac‐
175 ter sequence. The script will then fail because it found a match to the
176 abort string. If it received the string NO CARRIER, it will abort for
177 the same reason. Either string may be received. Either string will ter‐
178 minate the chat script.
179
181 This sequence allows for clearing previously set ABORT strings. ABORT
182 strings are kept in an array of a pre-determined size (at compilation
183 time); CLR_ABORT will reclaim the space for cleared entries so that new
184 strings can use that space.
185
187 The SAY directive allows the script to send strings to the user at the
188 terminal via standard error. If chat is being run by pppd, and pppd is
189 running as a daemon (detached from its controlling terminal), standard
190 error will normally be redirected to the file /etc/ppp/connect-errors.
191
192 SAY strings must be enclosed in single or double quotes. If carriage
193 return and line feed are needed in the string to be output, you must
194 explicitely add them to your string.
195
196 The SAY strings could be used to give progress messages in sections of
197 the script where you want to have 'ECHO OFF' but still let the user
198 know what is happening. An example is:
199
200 ABORT BUSY
201 ECHO OFF
202 SAY "Dialling your ISP...\n"
203 '' ATDT5551212
204 TIMEOUT 120
205 SAY "Waiting up to 2 minutes for connection ... "
206 CONNECT ''
207 SAY "Connected, now logging in ...0
208 ogin: account
209 ssword: pass
210 $ SAY "Logged in OK ...0 etc ...
211
212 This sequence will only present the SAY strings to the user and all the
213 details of the script will remain hidden. For example, if the above
214 script works, the user will see:
215
216 Dialling your ISP...
217 Waiting up to 2 minutes for connection ... Connected, now log‐
218 ging in ...
219 Logged in OK ...
220
222 A report string is similar to the ABORT string. The difference is that
223 the strings, and all characters to the next control character such as a
224 carriage return, are written to the report file.
225
226 The report strings may be used to isolate the transmission rate of the
227 modem's connect string and return the value to the chat user. The anal‐
228 ysis of the report string logic occurs in conjunction with the other
229 string processing such as looking for the expect string. The use of the
230 same string for a report and abort sequence is probably not very use‐
231 ful, however, it is possible.
232
233 The report strings to no change the completion code of the program.
234
235 These "report" strings may be specified in the script using the REPORT
236 sequence. It is written in the script as in the following example:
237
238 REPORT CONNECT ABORT BUSY '' ATDT5551212 CONNECT '' ogin:
239 account
240
241 This sequence will expect nothing; and then send the string ATDT5551212
242 to dial the telephone. The expected string is CONNECT. If the string
243 CONNECT is received the remainder of the script is executed. In addi‐
244 tion the program will write to the expect-file the string "CONNECT"
245 plus any characters which follow it such as the connection rate.
246
248 This sequence allows for clearing previously set REPORT strings.
249 REPORT strings are kept in an array of a pre-determined size (at compi‐
250 lation time); CLR_REPORT will reclaim the space for cleared entries so
251 that new strings can use that space.
252
254 The echo options controls whether the output from the modem is echoed
255 to stderr. This option may be set with the -e option, but it can also
256 be controlled by the ECHO keyword. The "expect-send" pair ECHO ON
257 enables echoing, and ECHO OFF disables it. With this keyword you can
258 select which parts of the conversation should be visible. For instance,
259 with the following script:
260
261 ABORT 'BUSY'
262 ABORT 'NO CARRIER'
263 OK\r\n ATD1234567
264 \r\n \c
265 ECHO ON
266 CONNECT \c
267 ogin: account
268
269 all output resulting from modem configuration and dialing is not visi‐
270 ble, but starting with the CONNECT (or BUSY) message, everything will
271 be echoed.
272
274 The HANGUP options control whether a modem hangup should be considered
275 as an error or not. This option is useful in scripts for dialling sys‐
276 tems which will hang up and call your system back. The HANGUP options
277 can be ON or OFF.
278 When HANGUP is set OFF and the modem hangs up (e.g., after the first
279 stage of logging in to a callback system), chat will continue running
280 the script (e.g., waiting for the incoming call and second stage login
281 prompt). As soon as the incoming call is connected, you should use the
282 HANGUP ON directive to reinstall normal hang up signal behavior. Here
283 is an (simple) example script:
284
285 ABORT 'BUSY'
286 OK\r\n ATD1234567
287 \r\n \c
288 CONNECT \c
289 'Callback login:' call_back_ID
290 HANGUP OFF
291 ABORT "Bad Login"
292 'Callback Password:' Call_back_password
293 TIMEOUT 120
294 CONNECT \c
295 HANGUP ON
296 ABORT "NO CARRIER"
297 ogin:--BREAK--ogin: real_account
298 etc ...
299
301 The initial timeout value is 45 seconds. This may be changed using the
302 -t parameter.
303
304 To change the timeout value for the next expect string, the following
305 example may be used:
306
307 ATZ OK ATDT5551212 CONNECT TIMEOUT 10 ogin:--ogin: TIMEOUT 5
308 assword: hello2u2
309
310 This will change the timeout to 10 seconds when it expects the login:
311 prompt. The timeout is then changed to 5 seconds when it looks for the
312 password prompt.
313
314 The timeout, once changed, remains in effect until it is changed again.
315
317 The special reply string of EOT indicates that the chat program should
318 send an EOT character to the remote. This is normally the End-of-file
319 character sequence. A return character is not sent following the EOT.
320 The EOT sequence may be embedded into the send string using the
321 sequence ^D.
322
324 The special reply string of BREAK will cause a break condition to be
325 sent. The break is a special signal on the transmitter. The normal pro‐
326 cessing on the receiver is to change the transmission rate. It may be
327 used to cycle through the available transmission rates on the remote
328 until you are able to receive a valid login prompt. The break sequence
329 may be embedded into the send string using the \K sequence.
330
332 The expect and reply strings may contain escape sequences. All of the
333 sequences are legal in the reply string. Many are legal in the expect.
334 Those which are not valid in the expect sequence are so indicated.
335
336 '' Expects or sends a null string. If you send a null string then
337 it will still send the return character. This sequence may
338 either be a pair of apostrophe or quote characters.
339
340 \b represents a backspace character.
341
342 \c Suppresses the newline at the end of the reply string. This is
343 the only method to send a string without a trailing return char‐
344 acter. It must be at the end of the send string. For example,
345 the sequence hello\c will simply send the characters h, e, l, l,
346 o. (not valid in expect.)
347
348 \d Delay for one second. The program uses sleep(1) which will delay
349 to a maximum of one second. (not valid in expect.)
350
351 \K Insert a BREAK (not valid in expect.)
352
353 \n Send a newline or linefeed character.
354
355 \N Send a null character. The same sequence may be represented by
356 \0. (not valid in expect.)
357
358 \p Pause for a fraction of a second. The delay is 1/10th of a sec‐
359 ond. (not valid in expect.)
360
361 \q Suppress writing the string to the SYSLOG file. The string
362 ?????? is written to the log in its place. (not valid in
363 expect.)
364
365 \r Send or expect a carriage return.
366
367 \s Represents a space character in the string. This may be used
368 when it is not desirable to quote the strings which contains
369 spaces. The sequence 'HI TIM' and HI\sTIM are the same.
370
371 \t Send or expect a tab character.
372
373 \T Send the phone number string as specified with the -T option
374 (not valid in expect.)
375
376 \U Send the phone number 2 string as specified with the -U option
377 (not valid in expect.)
378
379 \\ Send or expect a backslash character.
380
381 \ddd Collapse the octal digits (ddd) into a single ASCII character
382 and send that character. (some characters are not valid in
383 expect.)
384
385 ^C Substitute the sequence with the control character represented
386 by C. For example, the character DC1 (17) is shown as ^Q.
387 (some characters are not valid in expect.)
388
390 Environment variables are available within chat scripts, if the -E
391 option was specified in the command line. The metacharacter $ is used
392 to introduce the name of the environment variable to substitute. If the
393 substition fails, because the requested environment variable is not
394 set, nothing is replaced for the variable.
395
397 The chat program will terminate with the following completion codes.
398
399 0 The normal termination of the program. This indicates that the
400 script was executed without error to the normal conclusion.
401
402 1 One or more of the parameters are invalid or an expect string
403 was too large for the internal buffers. This indicates that the
404 program as not properly executed.
405
406 2 An error occurred during the execution of the program. This may
407 be due to a read or write operation failing for some reason or
408 chat receiving a signal such as SIGINT.
409
410 3 A timeout event occurred when there was an expect string without
411 having a "-subsend" string. This may mean that you did not pro‐
412 gram the script correctly for the condition or that some unex‐
413 pected event has occurred and the expected string could not be
414 found.
415
416 4 The first string marked as an ABORT condition occurred.
417
418 5 The second string marked as an ABORT condition occurred.
419
420 6 The third string marked as an ABORT condition occurred.
421
422 7 The fourth string marked as an ABORT condition occurred.
423
424 ... The other termination codes are also strings marked as an ABORT
425 condition.
426
427 Using the termination code, it is possible to determine which event
428 terminated the script. It is possible to decide if the string "BUSY"
429 was received from the modem as opposed to "NO DIAL TONE". While the
430 first event may be retried, the second will probably have little chance
431 of succeeding during a retry.
432
434 Additional information about chat scripts may be found with UUCP docu‐
435 mentation. The chat script was taken from the ideas proposed by the
436 scripts used by the uucico program.
437
438 uucico(1), uucp(1)
439
441 The chat program is in public domain. This is not the GNU public
442 license. If it breaks then you get to keep both pieces.
443
444
445
446Chat Version 1.22 22 May 1999 CHAT(8)