Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / usr.bin / chat / chat.8
1 .\" -*- nroff -*-
2 .\" manual page [] for chat 1.8
3 .\" $FreeBSD: src/usr.bin/chat/chat.8,v 1.15.2.3 2003/02/24 22:37:41 trhodes Exp $
4 .\" $DragonFly: src/usr.bin/chat/chat.8,v 1.2 2003/06/17 04:29:25 dillon Exp $
5 .\" SH section heading
6 .\" SS subsection heading
7 .\" LP paragraph
8 .\" IP indented paragraph
9 .\" TP hanging label
10 .TH CHAT 8 "27 Sep 1997" "Chat Version 1.17"
11 .SH NAME
12 chat \- Automated conversational script with a modem
13 .SH SYNOPSIS
14 .B chat
15 [
16 .I options
17 ]
18 .I script
19 .SH DESCRIPTION
20 .LP
21 The \fIchat\fR program defines a conversational exchange between the
22 computer and the modem.
23 Its primary purpose is to establish the
24 connection between the Point-to-Point Protocol Daemon (\fIpppd\fR) and
25 the remote's \fIpppd\fR process.
26 .SH OPTIONS
27 .TP
28 .B -f \fI<chat file>
29 Read the chat script from the chat \fIfile\fR.
30 The use of this option
31 is mutually exclusive with the chat script parameters.
32 The user must
33 have read access to the file.
34 Multiple lines are permitted in the
35 file.
36 Space or horizontal tab characters should be used to separate
37 the strings.
38 .TP
39 .B -t \fI<timeout>
40 Set the timeout for the expected string to be received.
41 If the string
42 is not received within the time limit then the reply string is not
43 sent.
44 An alternate reply may be sent or the script will fail if there
45 is no alternate reply string.
46 A failed script will cause the
47 \fIchat\fR program to terminate with a non-zero error code.
48 .TP
49 .B -r \fI<report file>
50 Set the file for output of the report strings.
51 If you use the keyword
52 \fIREPORT\fR, the resulting strings are written to this file.
53 If this
54 option is not used and you still use \fIREPORT\fR keywords, the
55 \fIstderr\fR file is used for the report strings.
56 .TP
57 .B -e
58 Start with the echo option turned on.
59 Echoing may also be turned on
60 or off at specific points in the chat script by using the \fIECHO\fR
61 keyword.
62 When echoing is enabled, all output from the modem is echoed
63 to \fIstderr\fR.
64 .TP
65 .B -v
66 Request that the \fIchat\fR script be executed in a verbose mode.
67 The
68 \fIchat\fR program will then log the execution state of the chat
69 script as well as all text received from the modem and the output
70 strings sent to the modem.  The default is to log through
71 .IR syslog (3);
72 the logging method may be altered with the -S and -s flags.
73 Logging is
74 done to the \fIlocal2\fR facility at level \fIinfo\fR for verbose tracing
75 and level \fIerr\fR for some errors.
76 .TP
77 .B -V
78 Request that the \fIchat\fR script be executed in a stderr verbose
79 mode.
80 The \fIchat\fR program will then log all text received from the
81 modem and the output strings sent to the modem to the stderr device.
82 This
83 device is usually the local console at the station running the chat or
84 pppd program.
85 .TP
86 .B -s
87 Use stderr.  All log messages from '-v' and all error messages will be
88 sent to stderr.
89 .TP
90 .B -S
91 Do not use
92 .IR syslog (3).
93 By default, error messages are sent to
94 .IR syslog (3).
95 The use of -S will prevent both log messages from '-v' and
96 error messages from being sent to
97 .IR syslog (3).
98 .TP
99 .B -T \fI<phone number>
100 Pass in an arbitrary string, usually a phone number, that will be
101 substituted for the \\T substitution metacharacter in a send string.
102 .TP
103 .B -U \fI<phone number 2>
104 Pass in a second string, usually a phone number, that will be
105 substituted for the \\U substitution metacharacter in a send string.
106 This is useful when dialing an ISDN terminal adapter that requires two
107 numbers.
108 .TP
109 .B script
110 If the script is not specified in a file with the \fI-f\fR option then
111 the script is included as parameters to the \fIchat\fR program.
112 .SH CHAT SCRIPT
113 .LP
114 The \fIchat\fR script defines the communications.
115 .LP
116 A script consists of one or more "expect-send" pairs of strings,
117 separated by spaces, with an optional "subexpect-subsend" string pair,
118 separated by a dash as in the following example:
119 .IP
120 ogin:-BREAK-ogin: ppp ssword: hello2u2
121 .LP
122 This line indicates that the \fIchat\fR program should expect the string
123 "ogin:". If it fails to receive a login prompt within the time interval
124 allotted, it is to send a break sequence to the remote and then expect the
125 string "ogin:". If the first "ogin:" is received then the break sequence is
126 not generated.
127 .LP
128 Once it received the login prompt the \fIchat\fR program will send the
129 string ppp and then expect the prompt "ssword:". When it receives the
130 prompt for the password, it will send the password hello2u2.
131 .LP
132 A carriage return is normally sent following the reply string.
133 It is not
134 expected in the "expect" string unless it is specifically requested by using
135 the \\r character sequence.
136 .LP
137 The expect sequence should contain only what is needed to identify the
138 string.
139 Since it is normally stored on a disk file, it should not contain
140 variable information.
141 It is generally not acceptable to look for time
142 strings, network identification strings, or other variable pieces of data as
143 an expect string.
144 .LP
145 To help correct for characters which may be corrupted during the initial
146 sequence, look for the string "ogin:" rather than "login:". It is possible
147 that the leading "l" character may be received in error and you may never
148 find the string even though it was sent by the system.
149 For this reason,
150 scripts look for "ogin:" rather than "login:" and "ssword:" rather than
151 "password:".
152 .LP
153 A very simple script might look like this:
154 .IP
155 ogin: ppp ssword: hello2u2
156 .LP
157 In other words, expect ....ogin:, send ppp, expect ...ssword:, send hello2u2.
158 .LP
159 In actual practice, simple scripts are rare.
160 At the vary least, you
161 should include sub-expect sequences should the original string not be
162 received.
163 For example, consider the following script:
164 .IP
165 ogin:--ogin: ppp ssword: hello2u2
166 .LP
167 This would be a better script than the simple one used earlier.
168 This would look
169 for the same login: prompt, however, if one was not received, a single
170 return sequence is sent and then it will look for login: again.
171 Should line
172 noise obscure the first login prompt then sending the empty line will
173 usually generate a login prompt again.
174 .SH COMMENTS
175 Comments can be embedded in the chat script.
176 A comment is a line which
177 starts with the \fB#\fR (hash) character in column 1. Such comment
178 lines are just ignored by the chat program.
179 If a '#' character is to
180 be expected as the first character of the expect sequence, you should
181 quote the expect string.
182 If you want to wait for a prompt that starts with a # (hash)
183 character, you would have to write something like this:
184 .IP
185 # Now wait for the prompt and send logout string
186 .br
187 \&'# ' logout
188 .LP
189
190 .SH ABORT STRINGS
191 Many modems will report the status of the call as a string.
192 These
193 strings may be \fBCONNECTED\fR or \fBNO CARRIER\fR or \fBBUSY\fR.
194 It
195 is often desirable to terminate the script should the modem fail to
196 connect to the remote.
197 The difficulty is that a script would not know
198 exactly which modem string it may receive.
199 On one attempt, it may
200 receive \fBBUSY\fR while the next time it may receive \fBNO CARRIER\fR.
201 .LP
202 These "abort" strings may be specified in the script using the \fIABORT\fR
203 sequence.
204 It is written in the script as in the following example:
205 .IP
206 ABORT BUSY ABORT 'NO CARRIER' '' ATZ OK ATDT5551212 CONNECT
207 .LP
208 This sequence will expect nothing; and then send the string ATZ.
209 The
210 expected response to this is the string \fIOK\fR.
211 When it receives \fIOK\fR,
212 the string ATDT5551212 to dial the telephone.
213 The expected string is
214 \fICONNECT\fR.
215 If the string \fICONNECT\fR is received the remainder of the
216 script is executed.
217 However, should the modem find a busy telephone, it will
218 send the string \fIBUSY\fR.
219 This will cause the string to match the abort
220 character sequence.
221 The script will then fail because it found a match to
222 the abort string.
223 If it received the string \fINO CARRIER\fR, it will abort
224 for the same reason.
225 Either string may be received.
226 Either string will
227 terminate the \fIchat\fR script.
228 .SH CLR_ABORT STRINGS
229 This sequence allows for clearing previously set \fBABORT\fR strings.
230 \fBABORT\fR strings are kept in an array of a pre-determined size (at
231 compilation time); \fBCLR_ABORT\fR will reclaim the space for cleared
232 entries so that new strings can use that space.
233 .SH SAY STRINGS
234 The \fBSAY\fR directive allows the script to send strings to the user
235 at the terminal via standard error.  If \fBchat\fR is being run by
236 pppd, and pppd is running as a daemon (detached from its controlling
237 terminal), standard error will normally be redirected to the file
238 /etc/ppp/connect-errors.
239 .LP
240 \fBSAY\fR strings must be enclosed in single or double quotes.
241 If
242 carriage return and line feed are needed in the string to be output,
243 you must explicitly add them to your string.
244 .LP
245 The SAY strings could be used to give progress messages in sections of
246 the script where you want to have 'ECHO OFF' but still let the user
247 know what is happening.  An example is:
248 .IP
249 ABORT BUSY
250 .br
251 ECHO OFF
252 .br
253 SAY "Dialling your ISP...\\n"
254 .br
255 \&'' ATDT5551212
256 .br
257 TIMEOUT 120
258 .br
259 SAY "Waiting up to 2 minutes for connection ... "
260 .br
261 CONNECT ''
262 .br
263 SAY "Connected, now logging in ...\\n"
264 .br
265 ogin: account
266 .br
267 ssword: pass
268 .br
269 $ \c
270 SAY "Logged in OK ...\\n"
271 \fIetc ...\fR
272 .LP
273 This sequence will only present the SAY strings to the user and all
274 the details of the script will remain hidden.
275 For example, if the
276 above script works, the user will see:
277 .IP
278 Dialling your ISP...
279 .br
280 Waiting up to 2 minutes for connection ... Connected, now logging in ...
281 .br
282 Logged in OK ...
283 .LP
284
285 .SH REPORT STRINGS
286 A \fBreport\fR string is similar to the ABORT string.
287 The difference
288 is that the strings, and all characters to the next control character
289 such as a carriage return, are written to the report file.
290 .LP
291 The report strings may be used to isolate the transmission rate of the
292 modem's connect string and return the value to the chat user.
293 The
294 analysis of the report string logic occurs in conjunction with the
295 other string processing such as looking for the expect string.
296 The use
297 of the same string for a report and abort sequence is probably not
298 very useful, however, it is possible.
299 .LP
300 The report strings to no change the completion code of the program.
301 .LP
302 These "report" strings may be specified in the script using the \fIREPORT\fR
303 sequence.
304 It is written in the script as in the following example:
305 .IP
306 REPORT CONNECT ABORT BUSY '' ATDT5551212 CONNECT '' ogin: account
307 .LP
308 This sequence will expect nothing; and then send the string
309 ATDT5551212 to dial the telephone.
310 The expected string is
311 \fICONNECT\fR.
312 If the string \fICONNECT\fR is received the remainder
313 of the script is executed.
314 In addition the program will write to the
315 expect-file the string "CONNECT" plus any characters which follow it
316 such as the connection rate.
317 .SH CLR_REPORT STRINGS
318 This sequence allows for clearing previously set \fBREPORT\fR strings.
319 \fBREPORT\fR strings are kept in an array of a pre-determined size (at
320 compilation time); \fBCLR_REPORT\fR will reclaim the space for cleared
321 entries so that new strings can use that space.
322 .SH ECHO
323 The echo options controls whether the output from the modem is echoed
324 to \fIstderr\fR.
325 This option may be set with the \fI-e\fR option, but
326 it can also be controlled by the \fIECHO\fR keyword.
327 The "expect-send"
328 pair \fIECHO\fR \fION\fR enables echoing, and \fIECHO\fR \fIOFF\fR
329 disables it.
330 With this keyword you can select which parts of the
331 conversation should be visible.
332 For instance, with the following
333 script:
334 .IP
335 ABORT   'BUSY'
336 .br
337 ABORT   'NO CARRIER'
338 .br
339 \&''      ATZ
340 .br
341 OK\\r\\n  ATD1234567
342 .br
343 \\r\\n    \\c
344 .br
345 ECHO    ON
346 .br
347 CONNECT \\c
348 .br
349 ogin:   account
350 .LP
351 all output resulting from modem configuration and dialing is not visible,
352 but starting with the \fICONNECT\fR (or \fIBUSY\fR) message, everything
353 will be echoed.
354 .SH HANGUP
355 The HANGUP options control whether a modem hangup should be considered
356 as an error or not.  This option is useful in scripts for dialling
357 systems which will hang up and call your system back.  The HANGUP
358 options can be \fBON\fR or \fBOFF\fR.
359 .br
360 When HANGUP is set OFF and the modem hangs up (e.g., after the first
361 stage of logging in to a callback system), \fBchat\fR will continue
362 running the script (e.g., waiting for the incoming call and second
363 stage login prompt). As soon as the incoming call is connected, you
364 should use the \fBHANGUP ON\fR directive to reinstall normal hang up
365 signal behavior.  Here is a (simple) example script:
366 .IP
367 ABORT   'BUSY'
368 .br
369 \&''      ATZ
370 .br
371 OK\\r\\n  ATD1234567
372 .br
373 \\r\\n    \\c
374 .br
375 CONNECT \\c
376 .br
377 \&'Callback login:' call_back_ID
378 .br
379 HANGUP OFF
380 .br
381 ABORT "Bad Login"
382 .br
383 \&'Callback Password:' Call_back_password
384 .br
385 TIMEOUT 120
386 .br
387 CONNECT \\c
388 .br
389 HANGUP ON
390 .br
391 ABORT "NO CARRIER"
392 .br
393 ogin:--BREAK--ogin: real_account
394 .br
395 \fIetc ...\fR
396 .LP
397 .SH TIMEOUT
398 The initial timeout value is 45 seconds.
399 This may be changed using the \fB-t\fR
400 parameter.
401 .LP
402 To change the timeout value for the next expect string, the following
403 example may be used:
404 .IP
405 ATZ OK ATDT5551212 CONNECT TIMEOUT 10 ogin:--ogin: TIMEOUT 5 assword: hello2u2
406 .LP
407 This will change the timeout to 10 seconds when it expects the login:
408 prompt.
409 The timeout is then changed to 5 seconds when it looks for the
410 password prompt.
411 .LP
412 The timeout, once changed, remains in effect until it is changed again.
413 .SH SENDING EOT
414 The special reply string of \fIEOT\fR indicates that the chat program
415 should send an EOT character to the remote.
416 This is normally the
417 End-of-file character sequence.
418 A return character is not sent
419 following the EOT.
420 .LP
421 The EOT sequence may be embedded into the send string using the
422 sequence \fI^D\fR.
423 .SH GENERATING BREAK
424 The special reply string of \fIBREAK\fR will cause a break condition
425 to be sent.
426 The break is a special signal on the transmitter.
427 The
428 normal processing on the receiver is to change the transmission rate.
429 It may be used to cycle through the available transmission rates on
430 the remote until you are able to receive a valid login prompt.
431 .LP
432 The break sequence may be embedded into the send string using the
433 \fI\\K\fR sequence.
434 .SH ESCAPE SEQUENCES
435 The expect and reply strings may contain escape sequences.
436 All of the
437 sequences are legal in the reply string.
438 Many are legal in the expect.
439 Those which are not valid in the expect sequence are so indicated.
440 .TP
441 .B ''
442 Expects or sends a null string.
443 If you send a null string then it will still
444 send the return character.
445 This sequence may either be a pair of apostrophe
446 or quote characters.
447 .TP
448 .B \\\\b
449 represents a backspace character.
450 .TP
451 .B \\\\c
452 Suppresses the newline at the end of the reply string.
453 This is the only
454 method to send a string without a trailing return character.
455 It must
456 be at the end of the send string.
457 For example,
458 the sequence hello\\c will simply send the characters h, e, l, l, o.
459 .I (not valid in expect.)
460 .TP
461 .B \\\\d
462 Delay for one second.
463 The program uses sleep(1) which will delay to a
464 maximum of one second.
465 .I (not valid in expect.)
466 .TP
467 .B \\\\K
468 Insert a BREAK
469 .I (not valid in expect.)
470 .TP
471 .B \\\\n
472 Send a newline or linefeed character.
473 .TP
474 .B \\\\N
475 Send a null character.
476 The same sequence may be represented by \\0.
477 .I (not valid in expect.)
478 .TP
479 .B \\\\p
480 Pause for a fraction of a second.
481 The delay is 1/10th of a second.
482 .I (not valid in expect.)
483 .TP
484 .B \\\\q
485 Suppress writing the string to
486 .IR syslogd (8).
487 The string ?????? is
488 written to the log in its place.
489 .I (not valid in expect.)
490 .TP
491 .B \\\\r
492 Send or expect a carriage return.
493 .TP
494 .B \\\\s
495 Represents a space character in the string.
496 This may be used when it
497 is not desirable to quote the strings which contains spaces.
498 The
499 sequence 'HI TIM' and HI\\sTIM are the same.
500 .TP
501 .B \\\\t
502 Send or expect a tab character.
503 .TP
504 .B \\\\\\\\
505 Send or expect a backslash character.
506 .TP
507 .B \\\\ddd
508 Collapse the octal digits (ddd) into a single ASCII character and send that
509 character.
510 .I (some characters are not valid in expect.)
511 .TP
512 .B \^^C
513 Substitute the sequence with the control character represented by C.
514 For example, the character DC1 (17) is shown as \^^Q.
515 .I (some characters are not valid in expect.)
516 .SH TERMINATION CODES
517 The \fIchat\fR program will terminate with the following completion
518 codes.
519 .TP
520 .B 0
521 The normal termination of the program.
522 This indicates that the script
523 was executed without error to the normal conclusion.
524 .TP
525 .B 1
526 One or more of the parameters are invalid or an expect string was too
527 large for the internal buffers.
528 This indicates that the program as not
529 properly executed.
530 .TP
531 .B 2
532 An error occurred during the execution of the program.
533 This may be due
534 to a read or write operation failing for some reason or chat receiving
535 a signal such as SIGINT.
536 .TP
537 .B 3
538 A timeout event occurred when there was an \fIexpect\fR string without
539 having a "-subsend" string.
540 This may mean that you did not program the
541 script correctly for the condition or that some unexpected event has
542 occurred and the expected string could not be found.
543 .TP
544 .B 4
545 The first string marked as an \fIABORT\fR condition occurred.
546 .TP
547 .B 5
548 The second string marked as an \fIABORT\fR condition occurred.
549 .TP
550 .B 6
551 The third string marked as an \fIABORT\fR condition occurred.
552 .TP
553 .B 7
554 The fourth string marked as an \fIABORT\fR condition occurred.
555 .TP
556 .B ...
557 The other termination codes are also strings marked as an \fIABORT\fR
558 condition.
559 .LP
560 Using the termination code, it is possible to determine which event
561 terminated the script.
562 It is possible to decide if the string "BUSY"
563 was received from the modem as opposed to "NO DIAL TONE". While the
564 first event may be retried, the second will probably have little
565 chance of succeeding during a retry.
566 .SH SEE ALSO
567 Additional information about \fIchat\fR scripts may be found with UUCP
568 documentation.
569 The \fIchat\fR script was taken from the ideas proposed
570 by the scripts used by the \fIuucico\fR program.
571 .LP
572 uucico(1), uucp(1), syslog(3), syslogd(8).
573 .SH COPYRIGHT
574 The \fIchat\fR program is in public domain.
575 This is not the GNU public
576 license.
577 If it breaks then you get to keep both pieces.