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.5 2007/07/29 17:27:45 swildner Exp $
10 .Nd Automated conversational script with a modem
15 .Op Fl r Ar report_file
17 .Op Fl T Ar phone_number
18 .Op Fl U Ar phone_number
22 program defines a conversational exchange between the computer and the modem.
23 Its primary purpose is to establish the
24 connection between the Point-to-Point Protocol Daemon
30 The following options are provided:
31 .Bl -tag -width ".Fl U Ar phone_number" -offset indent
33 Read the chat script from
35 The use of this option is mutually exclusive with the chat script parameters.
36 The user must have read access to the file.
37 Multiple lines are permitted in the file.
38 Space or horizontal tab characters should be used to separate the strings.
40 Set the timeout for the expected string to be received.
42 is not received within the time limit then the reply string is not sent.
43 An alternate reply may be sent or the script will fail if there
44 is no alternate reply string.
45 A failed script will cause the
47 program to terminate with a non-zero error code.
48 .It Fl r Ar report_file
49 Set the file for output of the report strings.
50 If you use the keyword
52 the resulting strings are written to this file.
53 If this option is not used and you still use
55 keywords, the stderr file is used for the report strings.
57 Start with the echo option turned on.
58 Echoing may also be turned on
59 or off at specific points in the chat script by using the
62 When echoing is enabled, all output from the modem is echoed to stderr.
66 be executed in a verbose mode.
69 program will then log the execution state of the chat
70 script as well as all text received from the modem and the output
71 strings sent to the modem.
72 The default is to log through
74 the logging method may be altered with the
79 Logging is done to the
83 for verbose tracing and level
89 be executed in a stderr verbose mode.
92 program will then log all text received from the
93 modem and the output strings sent to the modem to the stderr device.
95 device is usually the local console at the station running the chat or
101 and all error messages will be sent to stderr.
105 By default, error messages are sent to
109 will prevent both log messages from
111 and error messages from being sent to
113 .It Fl T Ar phone_number
114 Pass in an arbitrary string, usually a phone number, that will be
115 substituted for the \eT substitution metacharacter in a send string.
116 .It Fl U Ar phone_number
117 Pass in a second string, usually a phone number, that will be
118 substituted for the \eU substitution metacharacter in a send string.
119 This is useful when dialing an ISDN terminal adapter that requires two
122 If the script is not specified in a file with the
124 option then the script is included as parameters to the
131 script defines the communications.
133 A script consists of one or more
135 pairs of strings, separated by spaces, with an optional
136 .Dq subexpect-subsend
137 string pair, separated by a dash as in the following example:
139 .Dl ogin:-BREAK-ogin: ppp ssword: hello2u2
141 This line indicates that the
143 program should expect the string
145 If it fails to receive a login prompt within the time interval
146 allotted, it is to send a break sequence to the remote and then expect the
151 is received then the break sequence is not generated.
153 Once it received the login prompt the
155 program will send the string ppp and then expect the prompt
158 prompt for the password, it will send the password hello2u2.
160 A carriage return is normally sent following the reply string.
161 It is not expected in the
163 string unless it is specifically requested by using the \er character sequence.
165 The expect sequence should contain only what is needed to identify the string.
166 Since it is normally stored on a disk file, it should not contain
167 variable information.
168 It is generally not acceptable to look for time
169 strings, network identification strings, or other variable pieces of data as
172 To help correct for characters which may be corrupted during the initial
173 sequence, look for the string
177 It is possible that the leading
179 character may be received in error and you may never
180 find the string even though it was sent by the system.
181 For this reason, scripts look for
190 A very simple script might look like this:
192 .Dl ogin: ppp ssword: hello2u2
194 In other words, expect ....ogin:, send ppp, expect ...ssword:, send hello2u2.
196 In actual practice, simple scripts are rare.
197 At the vary least, you
198 should include sub-expect sequences should the original string not be
200 For example, consider the following script:
202 .Dl ogin:--ogin: ppp ssword: hello2u2
204 This would be a better script than the simple one used earlier.
206 for the same login: prompt, however, if one was not received, a single
207 return sequence is sent and then it will look for login: again.
209 noise obscure the first login prompt then sending the empty line will
210 usually generate a login prompt again.
212 Comments can be embedded in the chat script.
213 A comment is a line which
216 (hash) character in column 1.
217 Such comment lines are just ignored by the chat program.
221 be expected as the first character of the expect sequence, you should
222 quote the expect string.
223 If you want to wait for a prompt that starts with a # (hash)
224 character, you would have to write something like this:
225 .Bd -literal -offset indent
226 # Now wait for the prompt and send logout string
231 Many modems will report the status of the call as a string.
238 It is often desirable to terminate the script should the modem fail to
239 connect to the remote.
240 The difficulty is that a script would not know
241 exactly which modem string it may receive.
242 On one attempt, it may receive
244 while the next time it may receive
249 strings may be specified in the script using the
252 It is written in the script as in the following example:
254 .Dl ABORT BUSY ABORT 'NO CARRIER' '' ATZ OK ATDT5551212 CONNECT
256 This sequence will expect nothing; and then send the string ATZ.
257 The expected response to this is the string
261 the string ATDT5551212 to dial the telephone.
262 The expected string is
266 is received the remainder of the script is executed.
267 However, should the modem find a busy telephone, it will send the string
269 This will cause the string to match the abort character sequence.
270 The script will then fail because it found a match to the abort string.
271 If it received the string
273 it will abort for the same reason.
274 Either string may be received.
275 Either string will terminate the
278 .Sh CLR_ABORT STRINGS
279 This sequence allows for clearing previously set
283 strings are kept in an array of a pre-determined size (at compilation time);
284 .Dq CLR_ABORT will reclaim the space for cleared
285 entries so that new strings can use that space.
289 directive allows the script to send strings to the user
290 at the terminal via standard error.
294 pppd, and pppd is running as a daemon (detached from its controlling
295 terminal), standard error will normally be redirected to the file
296 .Pa /etc/ppp/connect-errors .
299 strings must be enclosed in single or double quotes.
300 If carriage return and line feed are needed in the string to be output,
301 you must explicitly add them to your string.
305 strings could be used to give progress messages in sections of
306 the script where you want to have
308 but still let the user know what is happening.
310 .Bd -literal -offset indent
313 SAY "Dialling your ISP...\\n"
317 SAY "Waiting up to 2 min. for connection... "
319 SAY "Connected, now logging in...\\n"
323 SAY "Logged in OK ...\\n"
327 This sequence will only present the SAY strings to the user and all
328 the details of the script will remain hidden.
329 For example, if the above script works, the user will see:
330 .Bd -literal -offset indent
332 Waiting up to 2 min. for connection... Connected, now logging in...
338 string is similar to the ABORT string.
340 is that the strings, and all characters to the next control character
341 such as a carriage return, are written to the report file.
343 The report strings may be used to isolate the transmission rate of the
344 modem's connect string and return the value to the chat user.
345 The analysis of the report string logic occurs in conjunction with the
346 other string processing such as looking for the expect string.
347 The use of the same string for a report and abort sequence is probably not
348 very useful, however, it is possible.
350 The report strings to no change the completion code of the program.
354 strings may be specified in the script using the
357 It is written in the script as in the following example:
359 .Dl REPORT CONNECT ABORT BUSY '' ATDT5551212 CONNECT '' ogin: account
361 This sequence will expect nothing; and then send the string
362 ATDT5551212 to dial the telephone.
363 The expected string is
367 is received the remainder of the script is executed.
368 In addition the program will write to the expect-file the string
370 plus any characters which follow it such as the connection rate.
371 .Sh CLR_REPORT STRINGS
372 This sequence allows for clearing previously set
376 strings are kept in an array of a pre-determined size (at compilation time);
378 will reclaim the space for cleared
379 entries so that new strings can use that space.
381 The echo options controls whether the output from the modem is echoed
383 This option may be set with the
385 option, but it can also be controlled by the
395 With this keyword you can select which parts of the
396 conversation should be visible.
397 For instance, with the following script:
398 .Bd -literal -offset indent
410 all output resulting from modem configuration and dialing is not visible,
411 but starting with the
415 message, everything will be echoed.
417 The HANGUP options control whether a modem hangup should be considered
418 as an error or not. This option is useful in scripts for dialling
419 systems which will hang up and call your system back. The HANGUP
425 When HANGUP is set OFF and the modem hangs up (e.g., after the first
426 stage of logging in to a callback system),
429 running the script (e.g.\&, waiting for the incoming call and second
430 stage login prompt). As soon as the incoming call is connected, you
433 directive to reinstall normal hang up signal behavior.
434 Here is a (simple) example script:
435 .Bd -literal -offset indent
443 \&'Callback login:' call_back_ID
447 \&'Callback Password:' Call_back_password
452 ogin:--BREAK--ogin: real_account
456 The initial timeout value is 45 seconds.
457 This may be changed using the
461 To change the timeout value for the next expect string, the following
464 .Dl ATZ OK ATDT5551212 CONNECT TIMEOUT 10 ogin:--ogin: TIMEOUT 5 assword: hello2u2
466 This will change the timeout to 10 seconds when it expects the login:
468 The timeout is then changed to 5 seconds when it looks for the
471 The timeout, once changed, remains in effect until it is changed again.
473 The special reply string of
475 indicates that the chat program should send an EOT character to the remote.
476 This is normally the End-of-file character sequence.
477 A return character is not sent following the EOT.
479 The EOT sequence may be embedded into the send string using the
483 The special reply string of
485 will cause a break condition to be sent.
486 The break is a special signal on the transmitter.
487 The normal processing on the receiver is to change the transmission rate.
488 It may be used to cycle through the available transmission rates on
489 the remote until you are able to receive a valid login prompt.
491 The break sequence may be embedded into the send string using the
495 The expect and reply strings may contain escape sequences.
496 All of the sequences are legal in the reply string.
497 Many are legal in the expect.
498 Those which are not valid in the expect sequence are so indicated.
499 .Bl -tag -width ".Li \e\e000"
501 Expects or sends a null string.
502 If you send a null string then it will still send the return character.
503 This sequence may either be a pair of apostrophe or quote characters.
505 represents a backspace character.
507 Suppresses the newline at the end of the reply string.
508 This is the only method to send a string without a trailing return character.
509 It must be at the end of the send string.
511 the sequence hello\ec will simply send the characters h, e, l, l, o.
512 .Em ( not valid in expect . )
514 Delay for one second.
517 which will delay to a maximum of one second.
518 .Em ( not valid in expect . )
521 .Em ( not valid in expect . )
523 Send a newline or linefeed character.
525 Send a null character.
526 The same sequence may be represented by \e0.
527 .Em ( not valid in expect . )
529 Pause for a fraction of a second.
530 The delay is 1/10th of a second.
531 .Em ( not valid in expect . )
533 Suppress writing the string to
536 written to the log in its place.
537 .Em ( not valid in expect . )
539 Send or expect a carriage return.
541 Represents a space character in the string.
542 This may be used when it
543 is not desirable to quote the strings which contains spaces.
550 Send or expect a tab character.
552 Send or expect a backslash character.
554 Collapse the octal digits (ddd) into a single ASCII character and send that
556 .Em ( some characters are not valid in expect . )
558 Substitute the sequence with the control character represented by C.
559 For example, the character DC1 (17) is shown as ^Q.
560 .Em ( some characters are not valid in expect . )
562 .Sh TERMINATION CODES
565 program will terminate with the following completion codes.
566 .Bl -tag -width ".Li ..."
568 The normal termination of the program.
569 This indicates that the script
570 was executed without error to the normal conclusion.
572 One or more of the parameters are invalid or an expect string was too
573 large for the internal buffers.
574 This indicates that the program as not properly executed.
576 An error occurred during the execution of the program.
578 to a read or write operation failing for some reason or chat receiving
579 a signal such as SIGINT.
581 A timeout event occurred when there was an
583 string without having a
586 This may mean that you did not program the
587 script correctly for the condition or that some unexpected event has
588 occurred and the expected string could not be found.
590 The first string marked as an
594 The second string marked as an
598 The third string marked as an
602 The fourth string marked as an
606 The other termination codes are also strings marked as an
611 Using the termination code, it is possible to determine which event
612 terminated the script.
613 It is possible to decide if the string
615 was received from the modem as opposed to
617 While the first event may be retried, the second will probably have little
618 chance of succeeding during a retry.
625 Additional information about
627 scripts may be found with UUCP documentation.
630 script was taken from the ideas proposed by the scripts used by the
636 program is in public domain.
637 This is not the GNU public license.
638 If it breaks then you get to keep both pieces.