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