1 .\" $NetBSD: chat.8,v 1.5 2009/10/14 17:35:41 joerg Exp $
4 .\" manual page [] for chat 1.8
5 .\" Id: chat.8,v 1.11 2004/11/13 12:22:49 paulus Exp
7 .\" SS subsection heading
9 .\" IP indented paragraph
11 .TH CHAT 8 "22 May 1999" "Chat Version 1.22"
13 chat \- Automated conversational script with a modem
22 The \fIchat\fR program defines a conversational exchange between the
23 computer and the modem.
24 Its primary purpose is to establish the
25 connection between the Point-to-Point Protocol Daemon (\fIpppd\fR) and
26 the remote's \fIpppd\fR process.
29 .B \-f \fI\*[Lt]chat file\*[Gt]
30 Read the chat script from the chat \fIfile\fR.
31 The use of this option
32 is mutually exclusive with the chat script parameters.
33 The user must have read access to the file.
34 Multiple lines are permitted in the file.
35 Space or horizontal tab characters should be used to separate
38 .B \-t \fI\*[Lt]timeout\*[Gt]
39 Set the timeout for the expected string to be received.
41 is not received within the time limit then the reply string is not
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
46 \fIchat\fR program to terminate with a non-zero error code.
48 .B \-r \fI\*[Lt]report file\*[Gt]
49 Set the file for output of the report strings.
50 If you use the keyword
51 \fIREPORT\fR, the resulting strings are written to this file.
53 option is not used and you still use \fIREPORT\fR keywords, the
54 \fIstderr\fR 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 \fIECHO\fR
61 When echoing is enabled, all output from the modem is echoed
65 Enables environment variable substitution within chat scripts using the
66 standard \fI$xxx\fR syntax.
69 Request that the \fIchat\fR script be executed in a verbose mode.
71 \fIchat\fR program will then log the execution state of the chat
72 script as well as all text received from the modem and the output
73 strings sent to the modem.
74 The default is to log through the SYSLOG;
75 the logging method may be altered with the \-S and \-s flags.
76 SYSLOGs are logged to facility LOG_LOCAL2.
79 Request that the \fIchat\fR script be executed in a stderr verbose
81 The \fIchat\fR program will then log all text received from the
82 modem and the output strings sent to the modem to the stderr device.
83 This device is usually the local console at the station running the chat or
88 All log messages from '\-v' and all error messages will be
92 Do not use the SYSLOG.
93 By default, error messages are sent to the SYSLOG.
94 The use of \-S will prevent both log messages from '\-v' and
95 error messages from being sent to the SYSLOG (to facility LOG_LOCAL2).
97 .B \-T \fI\*[Lt]phone number\*[Gt]
98 Pass in an arbitrary string, usually a phone number, that will be
99 substituted for the \\T substitution metacharacter in a send string.
101 .B \-U \fI\*[Lt]phone number 2\*[Gt]
102 Pass in a second string, usually a phone number, that will be
103 substituted for the \\U substitution metacharacter in a send string.
104 This is useful when dialing an ISDN terminal adapter that requires two
108 If the script is not specified in a file with the \fI\-f\fR option then
109 the script is included as parameters to the \fIchat\fR program.
112 The \fIchat\fR script defines the communications.
114 A script consists of one or more "expect\-send" pairs of strings,
115 separated by spaces, with an optional "subexpect\-subsend" string pair,
116 separated by a dash as in the following example:
118 ogin:\-BREAK\-ogin: ppp ssword: hello2u2
120 This line indicates that the \fIchat\fR program should expect the string
122 If it fails to receive a login prompt within the time interval
123 allotted, it is to send a break sequence to the remote and then expect the
125 If the first "ogin:" is received then the break sequence is
128 Once it received the login prompt the \fIchat\fR program will send the
129 string ppp and then expect the prompt "ssword:".
131 prompt for the password, it will send the password hello2u2.
133 A carriage return is normally sent following the reply string.
135 expected in the "expect" string unless it is specifically requested by using
136 the \\r character sequence.
138 The expect sequence should contain only what is needed to identify the
140 Since it is normally stored on a disk file, it should not contain
141 variable information.
142 It is generally not acceptable to look for time
143 strings, network identification strings, or other variable pieces of data as
146 To help correct for characters which may be corrupted during the initial
147 sequence, look for the string "ogin:" rather than "login:".
149 that the leading "l" character may be received in error and you may never
150 find the string even though it was sent by the system.
152 scripts look for "ogin:" rather than "login:" and "ssword:" rather than
155 A very simple script might look like this:
157 ogin: ppp ssword: hello2u2
159 In other words, expect ....ogin:, send ppp, expect ...ssword:, send hello2u2.
161 In actual practice, simple scripts are rare.
162 At the vary least, you
163 should include sub-expect sequences should the original string not be
165 For example, consider the following script:
167 ogin:\-\-ogin: ppp ssword: hello2u2
169 This would be a better script than the simple one used earlier.
171 for the same login: prompt, however, if one was not received, a single
172 return sequence is sent and then it will look for login: again.
174 noise obscure the first login prompt then sending the empty line will
175 usually generate a login prompt again.
177 Comments can be embedded in the chat script.
178 A comment is a line which
179 starts with the \fB#\fR (hash) character in column 1.
180 Such comment lines are just ignored by the chat program.
181 If a '#' character is to
182 be expected as the first character of the expect sequence, you should
183 quote the expect string.
184 If you want to wait for a prompt that starts with a # (hash)
185 character, you would have to write something like this:
187 # Now wait for the prompt and send logout string
192 .SH SENDING DATA FROM A FILE
193 If the string to send starts with an at sign (@), the rest of the
194 string is taken to be the name of a file to read to get the string to
196 If the last character of the data read is a newline, it is removed.
197 The file can be a named pipe (or fifo) instead of a regular file.
198 This provides a way for \fBchat\fR to communicate with another
199 program, for example, a program to prompt the user and receive a
204 Many modems will report the status of the call as a string.
206 strings may be \fBCONNECTED\fR or \fBNO CARRIER\fR or \fBBUSY\fR.
207 It is often desirable to terminate the script should the modem fail to
208 connect to the remote.
209 The difficulty is that a script would not know
210 exactly which modem string it may receive.
211 On one attempt, it may
212 receive \fBBUSY\fR while the next time it may receive \fBNO CARRIER\fR.
214 These "abort" strings may be specified in the script using the \fIABORT\fR
216 It is written in the script as in the following example:
218 ABORT BUSY ABORT 'NO CARRIER' '' ATZ OK ATDT5551212 CONNECT
220 This sequence will expect nothing; and then send the string ATZ.
221 The expected response to this is the string \fIOK\fR.
222 When it receives \fIOK\fR,
223 the string ATDT5551212 to dial the telephone.
224 The expected string is
226 If the string \fICONNECT\fR is received the remainder of the
228 However, should the modem find a busy telephone, it will
229 send the string \fIBUSY\fR.
230 This will cause the string to match the abort character sequence.
231 The script will then fail because it found a match to the abort string.
232 If it received the string \fINO CARRIER\fR, it will abort
234 Either string may be received.
235 Either string will terminate the \fIchat\fR script.
236 .SH CLR_ABORT STRINGS
237 This sequence allows for clearing previously set \fBABORT\fR strings.
238 \fBABORT\fR strings are kept in an array of a pre-determined size (at
239 compilation time); \fBCLR_ABORT\fR will reclaim the space for cleared
240 entries so that new strings can use that space.
242 The \fBSAY\fR directive allows the script to send strings to the user
243 at the terminal via standard error.
244 If \fBchat\fR is being run by
245 pppd, and pppd is running as a daemon (detached from its controlling
246 terminal), standard error will normally be redirected to the file
247 /etc/ppp/connect\-errors.
249 \fBSAY\fR strings must be enclosed in single or double quotes.
250 If carriage return and line feed are needed in the string to be output,
251 you must explicitly add them to your string.
253 The SAY strings could be used to give progress messages in sections of
254 the script where you want to have 'ECHO OFF' but still let the user
255 know what is happening.
262 SAY "Dialing your ISP...\\n"
268 SAY "Waiting up to 2 minutes for connection ... "
272 SAY "Connected, now logging in ...\\n"
279 SAY "Logged in OK ...\\n"
282 This sequence will only present the SAY strings to the user and all
283 the details of the script will remain hidden.
284 For example, if the above script works, the user will see:
288 Waiting up to 2 minutes for connection ... Connected, now logging in ...
294 A \fBreport\fR string is similar to the ABORT string.
296 is that the strings, and all characters to the next control character
297 such as a carriage return, are written to the report file.
299 The report strings may be used to isolate the transmission rate of the
300 modem's connect string and return the value to the chat user.
301 The analysis of the report string logic occurs in conjunction with the
302 other string processing such as looking for the expect string.
304 of the same string for a report and abort sequence is probably not
305 very useful, however, it is possible.
307 The report strings to no change the completion code of the program.
309 These "report" strings may be specified in the script using the \fIREPORT\fR
311 It is written in the script as in the following example:
313 REPORT CONNECT ABORT BUSY '' ATDT5551212 CONNECT '' ogin: account
315 This sequence will expect nothing; and then send the string
316 ATDT5551212 to dial the telephone.
317 The expected string is
319 If the string \fICONNECT\fR is received the remainder
320 of the script is executed.
321 In addition the program will write to the
322 expect\-file the string "CONNECT" plus any characters which follow it
323 such as the connection rate.
324 .SH CLR_REPORT STRINGS
325 This sequence allows for clearing previously set \fBREPORT\fR strings.
326 \fBREPORT\fR strings are kept in an array of a pre-determined size (at
327 compilation time); \fBCLR_REPORT\fR will reclaim the space for cleared
328 entries so that new strings can use that space.
330 The echo options controls whether the output from the modem is echoed
332 This option may be set with the \fI\-e\fR option, but
333 it can also be controlled by the \fIECHO\fR keyword.
335 pair \fIECHO\fR \fION\fR enables echoing, and \fIECHO\fR \fIOFF\fR
337 With this keyword you can select which parts of the
338 conversation should be visible.
339 For instance, with the following script:
357 all output resulting from modem configuration and dialing is not visible,
358 but starting with the \fICONNECT\fR (or \fIBUSY\fR) message, everything
361 The HANGUP options control whether a modem hangup should be considered
363 This option is useful in scripts for dialing
364 systems which will hang up and call your system back.
365 The HANGUP options can be \fBON\fR or \fBOFF\fR.
367 When HANGUP is set OFF and the modem hangs up (e.g., after the first
368 stage of logging in to a callback system), \fBchat\fR will continue
369 running the script (e.g., waiting for the incoming call and second
371 As soon as the incoming call is connected, you
372 should use the \fBHANGUP ON\fR directive to reinstall normal hang up
374 Here is an (simple) example script:
386 \&'Callback login:' call_back_ID
392 \&'Callback Password:' Call_back_password
402 ogin:\-\-BREAK\-\-ogin: real_account
407 The initial timeout value is 45 seconds.
408 This may be changed using the \fB\-t\fR parameter.
410 To change the timeout value for the next expect string, the following
413 ATZ OK ATDT5551212 CONNECT TIMEOUT 10 ogin:\-\-ogin: TIMEOUT 5 assword: hello2u2
415 This will change the timeout to 10 seconds when it expects the login:
417 The timeout is then changed to 5 seconds when it looks for the
420 The timeout, once changed, remains in effect until it is changed again.
422 The special reply string of \fIEOT\fR indicates that the chat program
423 should send an EOT character to the remote.
424 This is normally the End-of-file character sequence.
425 A return character is not sent following the EOT.
427 The EOT sequence may be embedded into the send string using the
430 The special reply string of \fIBREAK\fR will cause a break condition
432 The break is a special signal on the transmitter.
433 The normal processing on the receiver is to change the transmission rate.
434 It may be used to cycle through the available transmission rates on
435 the remote until you are able to receive a valid login prompt.
437 The break sequence may be embedded into the send string using the
440 The expect and reply strings may contain escape sequences.
441 All of the sequences are legal in the reply string.
442 Many are legal in the expect.
443 Those which are not valid in the expect sequence are so indicated.
446 Expects or sends a null string.
447 If you send a null string then it will still send the return character.
448 This sequence may either be a pair of apostrophe or quote characters.
451 represents a backspace character.
454 Suppresses the newline at the end of the reply string.
456 method to send a string without a trailing return character.
457 It must be at the end of the send string.
459 the sequence hello\\c will simply send the characters h, e, l, l, o.
460 .I (not valid in expect.)
463 Delay for one second.
464 The program uses sleep(1) which will delay to a maximum of one second.
465 .I (not valid in expect.)
469 .I (not valid in expect.)
472 Send a newline or linefeed character.
475 Send a null character.
476 The same sequence may be represented by \\0.
477 .I (not valid in expect.)
480 Pause for a fraction of a second.
481 The delay is 1/10th of a second.
482 .I (not valid in expect.)
485 Suppress writing the string to the SYSLOG.
486 The string ?????? is written to the log in its place.
487 .I (not valid in expect.)
490 Send or expect a carriage return.
493 Represents a space character in the string.
494 This may be used when it
495 is not desirable to quote the strings which contains spaces.
496 The sequence 'HI\ TIM' and HI\\sTIM are the same.
499 Send or expect a tab character.
502 Send the phone number string as specified with the \fI\-T\fR option
503 .I (not valid in expect.)
506 Send the phone number 2 string as specified with the \fI\-U\fR option
507 .I (not valid in expect.)
510 Send or expect a backslash character.
513 Collapse the octal digits (ddd) into a single ASCII character and send that
515 .I (some characters are not valid in expect.)
518 Substitute the sequence with the control character represented by C.
519 For example, the character DC1 (17) is shown as \^^Q.
520 .I (some characters are not valid in expect.)
521 .SH ENVIRONMENT VARIABLES
522 Environment variables are available within chat scripts, if the \fI\-E\fR
523 option was specified in the command line.
524 The metacharacter \fI$\fR is used
525 to introduce the name of the environment variable to substitute.
527 substitution fails, because the requested environment variable is not set,
528 \fInothing\fR is replaced for the variable.
529 .SH TERMINATION CODES
530 The \fIchat\fR program will terminate with the following completion
534 The normal termination of the program.
535 This indicates that the script
536 was executed without error to the normal conclusion.
539 One or more of the parameters are invalid or an expect string was too
540 large for the internal buffers.
541 This indicates that the program as not
545 An error occurred during the execution of the program.
547 to a read or write operation failing for some reason or chat receiving
548 a signal such as SIGINT.
551 A timeout event occurred when there was an \fIexpect\fR string without
552 having a "\-subsend" string.
553 This may mean that you did not program the
554 script correctly for the condition or that some unexpected event has
555 occurred and the expected string could not be found.
558 The first string marked as an \fIABORT\fR condition occurred.
561 The second string marked as an \fIABORT\fR condition occurred.
564 The third string marked as an \fIABORT\fR condition occurred.
567 The fourth string marked as an \fIABORT\fR condition occurred.
570 The other termination codes are also strings marked as an \fIABORT\fR
573 Using the termination code, it is possible to determine which event
574 terminated the script.
575 It is possible to decide if the string "BUSY"
576 was received from the modem as opposed to "NO DIAL TONE".
578 first event may be retried, the second will probably have little
579 chance of succeeding during a retry.
581 The \fIchat\fR program is in public domain.
582 This is not the GNU public license.
583 If it breaks then you get to keep both pieces.