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 substitution 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 arbitrary string, usually a phone number, that will
69 be 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 /var/log/ppp/con‐
191 nect-errors.
192
193 SAY strings must be enclosed in single or double quotes. If carriage
194 return and line feed are needed in the string to be output, you must
195 explicitly add them to your string.
196
197 The SAY strings could be used to give progress messages in sections of
198 the script where you want to have 'ECHO OFF' but still let the user
199 know what is happening. An example is:
200
201 ABORT BUSY
202 ECHO OFF
203 SAY "Dialling your ISP...\n"
204 '' ATDT5551212
205 TIMEOUT 120
206 SAY "Waiting up to 2 minutes for connection ... "
207 CONNECT ''
208 SAY "Connected, now logging in ...0
209 ogin: account
210 ssword: pass
211 $ SAY "Logged in OK ...0 etc ...
212
213 This sequence will only present the SAY strings to the user and all the
214 details of the script will remain hidden. For example, if the above
215 script works, the user will see:
216
217 Dialling your ISP...
218 Waiting up to 2 minutes for connection ... Connected, now log‐
219 ging in ...
220 Logged in OK ...
221
223 A report string is similar to the ABORT string. The difference is that
224 the strings, and all characters to the next control character such as a
225 carriage return, are written to the report file.
226
227 The report strings may be used to isolate the transmission rate of the
228 modem's connect string and return the value to the chat user. The anal‐
229 ysis of the report string logic occurs in conjunction with the other
230 string processing such as looking for the expect string. The use of the
231 same string for a report and abort sequence is probably not very use‐
232 ful, however, it is possible.
233
234 The report strings to no change the completion code of the program.
235
236 These "report" strings may be specified in the script using the REPORT
237 sequence. It is written in the script as in the following example:
238
239 REPORT CONNECT ABORT BUSY '' ATDT5551212 CONNECT '' ogin:
240 account
241
242 This sequence will expect nothing; and then send the string ATDT5551212
243 to dial the telephone. The expected string is CONNECT. If the string
244 CONNECT is received the remainder of the script is executed. In addi‐
245 tion the program will write to the expect-file the string "CONNECT"
246 plus any characters which follow it such as the connection rate.
247
249 This sequence allows for clearing previously set REPORT strings.
250 REPORT strings are kept in an array of a pre-determined size (at compi‐
251 lation time); CLR_REPORT will reclaim the space for cleared entries so
252 that new strings can use that space.
253
255 The echo options controls whether the output from the modem is echoed
256 to stderr. This option may be set with the -e option, but it can also
257 be controlled by the ECHO keyword. The "expect-send" pair ECHO ON
258 enables echoing, and ECHO OFF disables it. With this keyword you can
259 select which parts of the conversation should be visible. For instance,
260 with the following script:
261
262 ABORT 'BUSY'
263 ABORT 'NO CARRIER'
264 OK\r\n ATD1234567
265 \r\n \c
266 ECHO ON
267 CONNECT \c
268 ogin: account
269
270 all output resulting from modem configuration and dialing is not visi‐
271 ble, but starting with the CONNECT (or BUSY) message, everything will
272 be echoed.
273
275 The HANGUP options control whether a modem hangup should be considered
276 as an error or not. This option is useful in scripts for dialling sys‐
277 tems which will hang up and call your system back. The HANGUP options
278 can be ON or OFF.
279 When HANGUP is set OFF and the modem hangs up (e.g., after the first
280 stage of logging in to a callback system), chat will continue running
281 the script (e.g., waiting for the incoming call and second stage login
282 prompt). As soon as the incoming call is connected, you should use the
283 HANGUP ON directive to reinstall normal hang up signal behavior. Here
284 is an (simple) example script:
285
286 ABORT 'BUSY'
287 OK\r\n ATD1234567
288 \r\n \c
289 CONNECT \c
290 'Callback login:' call_back_ID
291 HANGUP OFF
292 ABORT "Bad Login"
293 'Callback Password:' Call_back_password
294 TIMEOUT 120
295 CONNECT \c
296 HANGUP ON
297 ABORT "NO CARRIER"
298 ogin:--BREAK--ogin: real_account
299 etc ...
300
302 The initial timeout value is 45 seconds. This may be changed using the
303 -t parameter.
304
305 To change the timeout value for the next expect string, the following
306 example may be used:
307
308 ATZ OK ATDT5551212 CONNECT TIMEOUT 10 ogin:--ogin: TIMEOUT 5
309 assword: hello2u2
310
311 This will change the timeout to 10 seconds when it expects the login:
312 prompt. The timeout is then changed to 5 seconds when it looks for the
313 password prompt.
314
315 The timeout, once changed, remains in effect until it is changed again.
316
318 The special reply string of EOT indicates that the chat program should
319 send an EOT character to the remote. This is normally the End-of-file
320 character sequence. A return character is not sent following the EOT.
321 The EOT sequence may be embedded into the send string using the
322 sequence ^D.
323
325 The special reply string of BREAK will cause a break condition to be
326 sent. The break is a special signal on the transmitter. The normal pro‐
327 cessing on the receiver is to change the transmission rate. It may be
328 used to cycle through the available transmission rates on the remote
329 until you are able to receive a valid login prompt. The break sequence
330 may be embedded into the send string using the \K sequence.
331
333 The expect and reply strings may contain escape sequences. All of the
334 sequences are legal in the reply string. Many are legal in the expect.
335 Those which are not valid in the expect sequence are so indicated.
336
337 '' Expects or sends a null string. If you send a null string then
338 it will still send the return character. This sequence may
339 either be a pair of apostrophe or quote characters.
340
341 \b represents a backspace character.
342
343 \c Suppresses the newline at the end of the reply string. This is
344 the only method to send a string without a trailing return char‐
345 acter. It must be at the end of the send string. For example,
346 the sequence hello\c will simply send the characters h, e, l, l,
347 o. (not valid in expect.)
348
349 \d Delay for one second. The program uses sleep(1) which will delay
350 to a maximum of one second. (not valid in expect.)
351
352 \K Insert a BREAK (not valid in expect.)
353
354 \n Send a newline or linefeed character.
355
356 \N Send a null character. The same sequence may be represented by
357 \0. (not valid in expect.)
358
359 \p Pause for a fraction of a second. The delay is 1/10th of a sec‐
360 ond. (not valid in expect.)
361
362 \q Suppress writing the string to the SYSLOG file. The string
363 ?????? is written to the log in its place. (not valid in
364 expect.)
365
366 \r Send or expect a carriage return.
367
368 \s Represents a space character in the string. This may be used
369 when it is not desirable to quote the strings which contains
370 spaces. The sequence 'HI TIM' and HI\sTIM are the same.
371
372 \t Send or expect a tab character.
373
374 \T Send the phone number string as specified with the -T option
375 (not valid in expect.)
376
377 \U Send the phone number 2 string as specified with the -U option
378 (not valid in expect.)
379
380 \\ Send or expect a backslash character.
381
382 \ddd Collapse the octal digits (ddd) into a single ASCII character
383 and send that character. (some characters are not valid in
384 expect.)
385
386 ^C Substitute the sequence with the control character represented
387 by C. For example, the character DC1 (17) is shown as ^Q.
388 (some characters are not valid in expect.)
389
391 Environment variables are available within chat scripts, if the -E
392 option was specified in the command line. The metacharacter $ is used
393 to introduce the name of the environment variable to substitute. If the
394 substitution fails, because the requested environment variable is not
395 set, nothing is replaced for the variable.
396
398 The chat program will terminate with the following completion codes.
399
400 0 The normal termination of the program. This indicates that the
401 script was executed without error to the normal conclusion.
402
403 1 One or more of the parameters are invalid or an expect string
404 was too large for the internal buffers. This indicates that the
405 program as not properly executed.
406
407 2 An error occurred during the execution of the program. This may
408 be due to a read or write operation failing for some reason or
409 chat receiving a signal such as SIGINT.
410
411 3 A timeout event occurred when there was an expect string without
412 having a "-subsend" string. This may mean that you did not pro‐
413 gram the script correctly for the condition or that some unex‐
414 pected event has occurred and the expected string could not be
415 found.
416
417 4 The first string marked as an ABORT condition occurred.
418
419 5 The second string marked as an ABORT condition occurred.
420
421 6 The third string marked as an ABORT condition occurred.
422
423 7 The fourth string marked as an ABORT condition occurred.
424
425 ... The other termination codes are also strings marked as an ABORT
426 condition.
427
428 Using the termination code, it is possible to determine which event
429 terminated the script. It is possible to decide if the string "BUSY"
430 was received from the modem as opposed to "NO DIAL TONE". While the
431 first event may be retried, the second will probably have little chance
432 of succeeding during a retry.
433
435 Additional information about chat scripts may be found with UUCP docu‐
436 mentation. The chat script was taken from the ideas proposed by the
437 scripts used by the uucico program.
438
439 uucico(1), uucp(1)
440
442 The chat program is in public domain. This is not the GNU public
443 license. If it breaks then you get to keep both pieces.
444
445
446
447Chat Version 1.22 22 May 1999 CHAT(8)