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