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 $
9 .Nd Automated conversational script with a modem
14 .Op Fl r Ar report_file
16 .Op Fl T Ar phone_number
17 .Op Fl U Ar phone_number
21 program defines a conversational exchange between the computer and the modem.
23 The following options are provided:
24 .Bl -tag -width ".Fl U Ar phone_number" -offset indent
26 Read the chat script from
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.
33 Set the timeout for the expected string to be received.
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
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
45 the resulting strings are written to this file.
46 If this option is not used and you still use
48 keywords, the stderr file is used for the report strings.
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
55 When echoing is enabled, all output from the modem is echoed to stderr.
59 be executed in a verbose mode.
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
67 the logging method may be altered with the
72 Logging is done to the
76 for verbose tracing and level
82 be executed in a stderr verbose mode.
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
95 and all error messages will be sent to stderr.
99 By default, error messages are sent to
103 will prevent both log messages from
105 and error messages from being sent to
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
116 If the script is not specified in a file with the
118 option then the script is included as parameters to the
125 script defines the communications.
127 A script consists of one or more
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:
133 .Dl ogin:-BREAK-ogin: ppp ssword: hello2u2
135 This line indicates that the
137 program should expect the string
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
145 is received then the break sequence is not generated.
147 Once it received the login prompt the
149 program will send the string ppp and then expect the prompt
152 prompt for the password, it will send the password hello2u2.
154 A carriage return is normally sent following the reply string.
155 It is not expected in the
157 string unless it is specifically requested by using the \er character sequence.
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
166 To help correct for characters which may be corrupted during the initial
167 sequence, look for the string
171 It is possible that the leading
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
184 A very simple script might look like this:
186 .Dl ogin: ppp ssword: hello2u2
188 In other words, expect ....ogin:, send ppp, expect ...ssword:, send hello2u2.
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
194 For example, consider the following script:
196 .Dl ogin:--ogin: ppp ssword: hello2u2
198 This would be a better script than the simple one used earlier.
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.
203 noise obscure the first login prompt then sending the empty line will
204 usually generate a login prompt again.
206 Comments can be embedded in the chat script.
207 A comment is a line which
210 (hash) character in column 1.
211 Such comment lines are just ignored by the chat program.
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
225 Many modems will report the status of the call as a string.
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
238 while the next time it may receive
243 strings may be specified in the script using the
246 It is written in the script as in the following example:
248 .Dl ABORT BUSY ABORT 'NO CARRIER' '' ATZ OK ATDT5551212 CONNECT
250 This sequence will expect nothing; and then send the string ATZ.
251 The expected response to this is the string
255 the string ATDT5551212 to dial the telephone.
256 The expected string is
260 is received the remainder of the script is executed.
261 However, should the modem find a busy telephone, it will send the string
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
267 it will abort for the same reason.
268 Either string may be received.
269 Either string will terminate the
272 .Sh CLR_ABORT STRINGS
273 This sequence allows for clearing previously set
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.
283 directive allows the script to send strings to the user
284 at the terminal via standard error.
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.
293 strings could be used to give progress messages in sections of
294 the script where you want to have
296 but still let the user know what is happening.
298 .Bd -literal -offset indent
301 SAY "Dialling your ISP...\\n"
305 SAY "Waiting up to 2 min. for connection... "
307 SAY "Connected, now logging in...\\n"
311 SAY "Logged in OK ...\\n"
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
320 Waiting up to 2 min. for connection... Connected, now logging in...
326 string is similar to the ABORT string.
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.
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.
338 The report strings to no change the completion code of the program.
342 strings may be specified in the script using the
345 It is written in the script as in the following example:
347 .Dl REPORT CONNECT ABORT BUSY '' ATDT5551212 CONNECT '' ogin: account
349 This sequence will expect nothing; and then send the string
350 ATDT5551212 to dial the telephone.
351 The expected string is
355 is received the remainder of the script is executed.
356 In addition the program will write to the expect-file the string
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
364 strings are kept in an array of a pre-determined size (at compilation time);
366 will reclaim the space for cleared
367 entries so that new strings can use that space.
369 The echo options controls whether the output from the modem is echoed
371 This option may be set with the
373 option, but it can also be controlled by the
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
398 all output resulting from modem configuration and dialing is not visible,
399 but starting with the
403 message, everything will be echoed.
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
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),
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
421 directive to reinstall normal hang up signal behavior.
422 Here is a (simple) example script:
423 .Bd -literal -offset indent
431 \&'Callback login:' call_back_ID
435 \&'Callback Password:' Call_back_password
440 ogin:--BREAK--ogin: real_account
444 The initial timeout value is 45 seconds.
445 This may be changed using the
449 To change the timeout value for the next expect string, the following
452 .Dl ATZ OK ATDT5551212 CONNECT TIMEOUT 10 ogin:--ogin: TIMEOUT 5 assword: hello2u2
454 This will change the timeout to 10 seconds when it expects the login:
456 The timeout is then changed to 5 seconds when it looks for the
459 The timeout, once changed, remains in effect until it is changed again.
461 The special reply string of
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.
467 The EOT sequence may be embedded into the send string using the
471 The special reply string of
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.
479 The break sequence may be embedded into the send string using the
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"
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.
493 represents a backspace character.
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.
499 the sequence hello\ec will simply send the characters h, e, l, l, o.
500 .Em ( not valid in expect . )
502 Delay for one second.
505 which will delay to a maximum of one second.
506 .Em ( not valid in expect . )
509 .Em ( not valid in expect . )
511 Send a newline or linefeed character.
513 Send a null character.
514 The same sequence may be represented by \e0.
515 .Em ( not valid in expect . )
517 Pause for a fraction of a second.
518 The delay is 1/10th of a second.
519 .Em ( not valid in expect . )
521 Suppress writing the string to
524 written to the log in its place.
525 .Em ( not valid in expect . )
527 Send or expect a carriage return.
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.
538 Send or expect a tab character.
540 Send or expect a backslash character.
542 Collapse the octal digits (ddd) into a single ASCII character and send that
544 .Em ( some characters are not valid in expect . )
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 . )
550 .Sh TERMINATION CODES
553 program will terminate with the following completion codes.
554 .Bl -tag -width ".Li ..."
556 The normal termination of the program.
557 This indicates that the script
558 was executed without error to the normal conclusion.
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.
564 An error occurred during the execution of the program.
566 to a read or write operation failing for some reason or chat receiving
570 A timeout event occurred when there was an
572 string without having a
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.
579 The first string marked as an
583 The second string marked as an
587 The third string marked as an
591 The fourth string marked as an
595 The other termination codes are also strings marked as an
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
604 was received from the modem as opposed to
606 While the first event may be retried, the second will probably have little
607 chance of succeeding during a retry.
609 .Xr uucp 1 Pq Pa net/freebsd-uucp ,
612 .Xr uucico 8 Pq Pa net/freebsd-uucp
614 Additional information about
616 scripts may be found with UUCP documentation.
619 script was taken from the ideas proposed by the scripts used by the
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.