]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - usr.bin/chat/chat.8
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.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.  An example is:
295 .Bd -literal -offset indent
296 ABORT BUSY
297 ECHO OFF
298 SAY "Dialling your ISP...\\n"
299 \&'' ATDT5551212
300 TIMEOUT 120
301 SAY "Waiting up to 2 minutes for connection ... "
302 CONNECT ''
303 SAY "Connected, now logging in ...\\n"
304 ogin: account
305 ssword: pass
306 $ SAY "Logged in OK ...\\n" \fIetc ...\fR
307 .Ed
308 .Pp
309 This sequence will only present the
310 .Dv SAY
311 strings to the user and all
312 the details of the script will remain hidden.
313 For example, if the
314 above script works, the user will see:
315 .Bd -literal -offset indent
316 Dialling your ISP...
317 Waiting up to 2 minutes for connection ... Connected, now logging in ...
318 Logged in OK ...
319 .Ed
320 .Sh REPORT STRINGS
321 A report string is similar to the
322 .Dv ABORT
323 string.
324 The difference
325 is that the strings, and all characters to the next control character
326 such as a carriage return, are written to the report file.
327 .Pp
328 The report strings may be used to isolate the transmission rate of the
329 modem's connect string and return the value to the chat user.
330 The
331 analysis of the report string logic occurs in conjunction with the
332 other string processing such as looking for the expect string.
333 The use
334 of the same string for a report and abort sequence is probably not
335 very useful, however, it is possible.
336 .Pp
337 The report strings to no change the completion code of the program.
338 .Pp
339 These "report" strings may be specified in the script using the
340 .Dv REPORT
341 sequence.
342 It is written in the script as in the following example:
343 .Pp
344 .D1 REPORT CONNECT ABORT BUSY '' ATDT5551212 CONNECT '' ogin: account
345 .Pp
346 This sequence will expect nothing; and then send the string
347 ATDT5551212 to dial the telephone.
348 The expected string is
349 .Dv CONNECT .
350 If the string
351 .Dv CONNECT
352 is received the remainder
353 of the script is executed.
354 In addition the program will write to the
355 expect-file the string "CONNECT" plus any characters which follow it
356 such as the connection rate.
357 .Sh CLR_REPORT STRINGS
358 This sequence allows for clearing previously set
359 .Dv REPORT
360 strings.
361 .Dv REPORT
362 strings are kept in an array of a pre-determined size (at
363 compilation time); CLR_REPORT will reclaim the space for cleared
364 entries so that new strings can use that space.
365 .Sh ECHO
366 The echo options controls whether the output from the modem is echoed
367 to
368 .Em stderr .
369 This option may be set with the
370 .Fl e
371 option, but
372 it can also be controlled by the
373 .Dv ECHO
374 keyword.
375 The "expect-send"
376 pair
377 .Dv ECHO ON
378 enables echoing, and
379 .Dv ECHO OFF
380 disables it.
381 With this keyword you can select which parts of the
382 conversation should be visible.
383 For instance, with the following
384 script:
385 .Bd -literal -offset indent
386 ABORT   'BUSY'
387 ABORT   'NO CARRIER'
388 \&''      ATZ
389 OK\\r\\n  ATD1234567
390 \\r\\n    \\c
391 ECHO    ON
392 CONNECT \\c
393 ogin:   account
394 .Ed
395 .Pp
396 all output resulting from modem configuration and dialing is not visible,
397 but starting with the
398 .Dv CONNECT
399 or
400 .Dv BUSY
401 message, everything
402 will be echoed.
403 .Sh HANGUP
404 The
405 .Dv HANGUP
406 options control whether a modem hangup should be considered
407 as an error or not.
408 This option is useful in scripts for dialling
409 systems which will hang up and call your system back.
410 The
411 .Dv HANGUP
412 options can be
413 .Dv ON
414 or
415 .Dv OFF .
416 .Pp
417 When
418 .Dv HANGUP
419 is set
420 .Dv OFF
421 and the modem hangs up (e.g., after the first
422 stage of logging in to a callback system),
423 .Nm
424 will continue
425 running the script (e.g., waiting for the incoming call and second
426 stage login prompt).
427 As soon as the incoming call is connected, you
428 should use the
429 .Dv HANGUP ON
430 directive to reinstall normal hang up
431 signal behavior.
432 Here is a (simple) example script:
433 .Bd -literal -offset indent
434 ABORT   'BUSY'
435 \&''      ATZ
436 OK\\r\\n  ATD1234567
437 \\r\\n    \\c
438 CONNECT \\c
439 \&'Callback login:' call_back_ID
440 HANGUP OFF
441 ABORT "Bad Login"
442 \&'Callback Password:' Call_back_password
443 TIMEOUT 120
444 CONNECT \\c
445 HANGUP ON
446 ABORT "NO CARRIER"
447 ogin:--BREAK--ogin: real_account
448 \fIetc ...\fR
449 .Ed
450 .Sh TIMEOUT
451 The initial timeout value is 45 seconds.
452 This may be changed using the
453 .Fl t
454 parameter.
455 .Pp
456 To change the timeout value for the next expect string, the following
457 example may be used:
458 .Bd -literal -offset indent
459 ATZ OK ATDT5551212 CONNECT TIMEOUT 10 ogin:--ogin: TIMEOUT 5 assword: hello2u2
460 .Ed
461 .Pp
462 This will change the timeout to 10 seconds when it expects the login:
463 prompt.
464 The timeout is then changed to 5 seconds when it looks for the
465 password prompt.
466 .Pp
467 The timeout, once changed, remains in effect until it is changed again.
468 .Sh SENDING EOT
469 The special reply string of
470 .Dv EOT
471 indicates that the chat program
472 should send an
473 .Dv EOT
474 character to the remote.
475 This is normally the
476 End-of-file character sequence.
477 A return character is not sent
478 following the
479 .Dv EOT .
480 .Pp
481 The
482 .Dv EOT
483 sequence may be embedded into the send string using the
484 sequence ^D.
485 .Sh GENERATING BREAK
486 The special reply string of
487 .Dv BREAK
488 will cause a break condition
489 to be sent.
490 The break is a special signal on the transmitter.
491 The
492 normal processing on the receiver is to change the transmission rate.
493 It may be used to cycle through the available transmission rates on
494 the remote until you are able to receive a valid login prompt.
495 .Pp
496 The break sequence may be embedded into the send string using the
497 \fI\\K\fR sequence.
498 .Sh ESCAPE SEQUENCES
499 The expect and reply strings may contain escape sequences.
500 All of the
501 sequences are legal in the reply string.
502 Many are legal in the expect.
503 Those which are not valid in the expect sequence are so indicated.
504 .Bl -tag -width indent
505 .It ''
506 Expects or sends a null string.
507 If you send a null string then it will still
508 send the return character.
509 This sequence may either be a pair of apostrophe
510 or quote characters.
511 .It \eb
512 represents a backspace character.
513 .It \ec
514 Suppresses the newline at the end of the reply string.
515 This is the only
516 method to send a string without a trailing return character.
517 It must
518 be at the end of the send string.
519 For example,
520 the sequence hello\\c will simply send the characters h, e, l, l, o
521 .Pq Em not valid in expect .
522 .It \ed
523 Delay for one second.
524 The program uses sleep(1) which will delay to a
525 maximum of one second
526 .Pq Em not valid in expect .
527 .It \eK
528 Insert a
529 .Dv BREAK
530 .Pq Em not valid in expect .
531 .It \en
532 Send a newline or linefeed character.
533 .It \eN
534 Send a null character.
535 The same sequence may be represented by \\0
536 .Pq Em not valid in expect .
537 .It \ep
538 Pause for a fraction of a second.
539 The delay is 1/10th of a second
540 .Pq Em not valid in expect .
541 .It \eq
542 Suppress writing the string to
543 .Xr syslogd 8 .
544 The string ?????? is
545 written to the log in its place
546 .Pq Em not valid in expect .
547 .It \er
548 Send or expect a carriage return.
549 .It \es
550 Represents a space character in the string.
551 This may be used when it
552 is not desirable to quote the strings which contains spaces.
553 The
554 sequence 'HI TIM' and HI\\sTIM are the same.
555 .It \et
556 Send or expect a tab character.
557 .It \e
558 Send or expect a backslash character.
559 .It \eddd
560 Collapse the octal digits (ddd) into a single ASCII character and send that
561 character
562 .Pq Em some characters are not valid in expect .
563 .It \^^C
564 Substitute the sequence with the control character represented by C.
565 For example, the character DC1 (17) is shown as \^^Q
566 .Pq Em some characters are not valid in expect .
567 .El
568 .Sh TERMINATION CODES
569 The
570 .Nm
571 program will terminate with the following completion
572 codes.
573 .Bl -tag -width indent
574 .It 0
575 The normal termination of the program.
576 This indicates that the script
577 was executed without error to the normal conclusion.
578 .It 1
579 One or more of the parameters are invalid or an expect string was too
580 large for the internal buffers.
581 This indicates that the program as not
582 properly executed.
583 .It 2
584 An error occurred during the execution of the program.
585 This may be due
586 to a read or write operation failing for some reason or chat receiving
587 a signal such as
588 .Dv SIGINT .
589 .It 3
590 A timeout event occurred when there was an
591 .Em expect
592 string without
593 having a "-subsend" string.
594 This may mean that you did not program the
595 script correctly for the condition or that some unexpected event has
596 occurred and the expected string could not be found.
597 .It 4
598 The first string marked as an
599 .Dv ABORT
600 condition occurred.
601 .It 5
602 The second string marked as an
603 .Dv ABORT
604 condition occurred.
605 .It 6
606 The third string marked as an
607 .Dv ABORT
608 condition occurred.
609 .It 7
610 The fourth string marked as an
611 .Dv ABORT
612 condition occurred.
613 .It ...
614 The other termination codes are also strings marked as an
615 .Dv ABORT
616 condition.
617 .El
618 .Pp
619 Using the termination code, it is possible to determine which event
620 terminated the script.
621 It is possible to decide if the string "BUSY"
622 was received from the modem as opposed to "NO DIAL TONE".
623 While the
624 first event may be retried, the second will probably have little
625 chance of succeeding during a retry.
626 .Sh SEE ALSO
627 Additional information about
628 .Nm
629 scripts may be found with UUCP
630 documentation.
631 The
632 .Nm
633 script was taken from the ideas proposed
634 by the scripts used by the uucico program.
635 .Pp
636 .Xr syslog 3 ,
637 .Xr syslogd 8
638 .Sh COPYRIGHT
639 The
640 .Nm
641 program is in public domain.
642 This is not the GNU public
643 license.
644 If it breaks then you get to keep both pieces.