Move /var/svc/log to /var/log/svc
[unleashed/lotheac.git] / share / man / man8 / chat.8
blobe8f1034c541e35e8b2037ccb1002de55e47fb98f
1 '\" te
2 .\" This manual page is based on documentation obtained from Karl Fox.
3 .\" Portions Copyright (C) 2008, Sun Microsystems, Inc. All Rights Reserved
4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
5 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
6 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH CHAT 8 "April 9, 2016"
8 .SH NAME
9 chat \- automated conversational exchange tool
10 .SH SYNOPSIS
11 .LP
12 .nf
13 \fBchat\fR [\fIoptions\fR] \fIscript\fR
14 .fi
16 .SH DESCRIPTION
17 .LP
18 The \fBchat\fR program implements a conversational text-based exchange between
19 the computer and any serial device, including (but not limited to) a modem, an
20 ISDN TA, and the remote peer itself, establishing a connection between the
21 Point-To-Point Protocol daemon (\fBpppd\fR) and the remote \fBpppd\fR process.
22 .SH OPTIONS
23 .LP
24 The  \fBchat\fR command supports the following options:
25 .sp
26 .ne 2
27 .na
28 \fB\fB-f\fR \fI<chat file>\fR\fR
29 .ad
30 .RS 23n
31 Read the \fBchat\fR script from the  \fBchat\fR file. This option is mutually
32 exclusive with the  \fBchat\fR script parameters. You must have \fBread\fR
33 access to use the file. Multiple lines are permitted in the file. Use the space
34 or horizontal tab characters to separate the strings.
35 .RE
37 .sp
38 .ne 2
39 .na
40 \fB\fB-t\fR \fB\fI<timeout>\fR\fR \fR
41 .ad
42 .RS 23n
43 Set the timeout for the expected string to be received. If the string is not
44 received within the time limit, the reply string is not sent. If specified,
45 a 'subexpect' (alternate reply) string can be sent. Otherwise, if no alternate
46 reply strings remain, the \fBchat\fR script fails.. A failed script will cause
47 the  \fBchat\fR program to terminate with a non-zero error code.
48 .RE
50 .sp
51 .ne 2
52 .na
53 \fB\fB-r\fR \fB\fI<report file> \fR\fR \fR
54 .ad
55 .RS 23n
56 Set the file for output of the report strings. If you use the keyword
57 \fBREPORT\fR, the resulting strings are written to this file. If  the \fB-r\fR
58 option is not used and you use the \fBREPORT\fR keyword, the  \fBstderr\fR file
59 is used for the report strings.
60 .RE
62 .sp
63 .ne 2
64 .na
65 \fB\fB-e\fR \fR
66 .ad
67 .RS 23n
68 Start with the echo option turned on. You turn echo on or off at specific
69 points in the \fBchat\fR script using the \fBECHO\fR keyword. When echoing is
70 enabled, all output from the modem is echoed to \fBstderr\fR.
71 .RE
73 .sp
74 .ne 2
75 .na
76 \fB\fB-E\fR \fR
77 .ad
78 .RS 23n
79 Enables environment variable substitution within \fBchat\fR scripts using the
80 standard \fI$xxx\fR syntax.
81 .RE
83 .sp
84 .ne 2
85 .na
86 \fB\fB-v\fR \fR
87 .ad
88 .RS 23n
89 Request that the \fBchat\fR script execute in a verbose mode. The  \fBchat\fR
90 program logs the execution state of the \fBchat\fR script as well as all text
91 received from the modem and output strings sent to the modem. The default is to
92 log through \fBsyslog\fR(3C) with facility \fBlocal\fR2; the logging method is
93 alterable using the \fB-S\fR and \fB-s\fR options.
94 .RE
96 .sp
97 .ne 2
98 .na
99 \fB\fB-V\fR \fR
101 .RS 23n
102 Request that the  \fBchat\fR script be executed in a \fBstderr\fR verbose mode.
103 The \fBchat\fR program logs all text received from the modem and output strings
104 sent to the modem to \fBstderr\fR. \fBstderr\fR is usually the local console at
105 the station running the  \fBchat\fR or \fBpppd\fR program.
109 .ne 2
111 \fB\fB-s\fR\fR
113 .RS 23n
114 Use \fBstderr\fR.  Log messages from \fB-v\fR and error messages are sent to
115 \fBstderr\fR.
119 .ne 2
121 \fB\fB-S\fR\fR
123 .RS 23n
124 Do not use syslog.  By default, error messages are set to syslog. This option
125 prevents log messages from \fB-v\fR and error messages from being sent to
126 syslog.
130 .ne 2
132 \fB\fB-T\fR \fB\fI<phone number>\fR\fR\fR
134 .RS 23n
135 Pass in an arbitrary string (usually a telephone number) that will be
136 substituted for the \fB\eT\fR substitution metacharacter in a send string.
140 .ne 2
142 \fB\fB-U\fR \fB\fI<phone number 2>\fR\fR\fR
144 .RS 23n
145 Pass in a second string (usually a telephone number) that will be substituted
146 for the \fB\eU\fR substitution metacharacter in a send string. This is useful
147 when dialing an ISDN terminal adapter that requires two numbers.
151 .ne 2
153 \fB\fBscript\fR \fR
155 .RS 23n
156 If the script is not specified in a file with the \fB-f\fR option, the script
157 is included as parameters to the \fBchat\fR program.
160 .SH EXTENDED DESCRIPTION
161 .SS "Chat Script"
163 The \fBchat\fR script defines communications. A script consists of one or more
164 "expect-send" pairs of strings separated by spaces, with an optional
165 "subexpect-subsend" string pair, separated by a dash (as in the following
166 example:)
169 ogin:-BREAK-ogin: ppp ssword: hello2u2
172 The example indicates that the \fBchat\fR program should expect the string
173 "ogin:". If it fails to receive a login prompt within the time interval
174 allotted, it sends a break sequence to the remote and then expects the string
175 "ogin:". If the first "ogin:" is received, the break sequence is not generated.
178 Upon receiving the login prompt, the  \fBchat\fR program sends the string "ppp"
179 and then expects the prompt "ssword:". When the password prompt is received, it
180 sends the password hello2u2.
183 A carriage return is normally sent following the reply string. It is not
184 expected in the "expect" string unless it is specifically requested by using
185 the \fB\er\fR character sequence.
188 The expect sequence should contain only what is needed to identify the received
189 data. Because it's stored on a disk file, it should not contain variable
190 information. Generally it is not acceptable to look for time strings, network
191 identification strings, or other variable pieces of data as an expect string.
194 To correct for characters that are corrupted during the initial sequence, look
195 for the string "ogin:" rather than "login:". The leading "l" character may be
196 received in error, creating problems in finding the string. For this reason,
197 scripts look for "ogin:" rather than "login:" and "ssword:" rather than
198 "password:".
201 An example of a simple script follows:
203 .in +2
205 ogin: ppp ssword: hello2u2
207 .in -2
211 The example can be intrepreted as: expect ogin:, send ppp, expect ...ssword:,
212 send hello2u2.
215 When login to a remote peer is necessary, simple scripts are rare. At minimum,
216 you should include sub-expect sequences in case the original string is not
217 received. For example, consider the following script:
219 .in +2
221 ogin:--ogin: ppp ssword: hello2u2
223 .in -2
227 This script is more effective than the simple one used earlier. The string
228 looks for the same login prompt; however, if one is not received, a single
229 return sequence is sent and then the script looks for login: again. If line
230 noise obscures the first login prompt, send the empty line to generate a login
231 prompt again.
232 .SS "Comments"
234 Comments can be embedded in the \fBchat\fR script. Comment lines are ignored by
235 the chat program. A comment starts with the hash ("#") character in column one.
236 If a \fB#\fR character is expected as the first character of the expect
237 sequence, quote the expect string. If you want to wait for a prompt that starts
238 with a \fB#\fR character, write something like this:
240 .in +2
242 # Now wait for the prompt and send logout string
243 \&'# ' logout
245 .in -2
247 .SS "Sending Data From A File"
249 If the string to send begins with an at sign ("@"), the remainder of the string
250 is interpreted as the name of the file that contains the string. If the last
251 character of the data read is a newline, it is removed. The file can be a named
252 pipe (or fifo) instead of a regular file. This enables \fBchat\fR to
253 communicate with another program, for example, a program to prompt the user and
254 receive a password typed in.
255 .SS "Abort "
257 Many modems report the status of a call as a string. These status strings are
258 often "CONNECTED" or "NO CARRIER" or "BUSY." If the modem fails to connect to
259 the remote, you can terminate the script. Abort strings may be specified in the
260 script using the ABORT sequence. For example:
262 .in +2
264 ABORT BUSY ABORT 'NO CARRIER' '' ATZ OK ATDT5551212 CONNECT
266 .in -2
270 This sequence expects nothing and sends the string ATZ. The expected response
271 is the string OK. When OK is received, the string ATDT5551212 dials the
272 telephone. The expected string is CONNECT. If CONNECT is received, the
273 remainder of the script is executed. When the modem finds a busy telephone, it
274 sends the string BUSY, causing the string to match the abort character
275 sequence. The script fails because it found a match to the abort string. If the
276 NO CARRIER string is received, it aborts for the same reason.
277 .SS "Clr_Abort "
279 The CLR_ABORT sequence clears previously set ABORT strings. ABORT strings are
280 kept in an array of a pre-determined size; CLR_ABORT reclaims the space for
281 cleared entries, enabling new strings to use that space.
282 .SS "Say "
284 The SAY string enables the script to send strings to a user at a terminal via
285 standard error. If \fBchat\fR is being run by \fBpppd\fR and \fBpppd\fR is
286 running as a daemon (detached from its controlling terminal), standard error is
287 normally redirected to the \fB/etc/ppp/connect-errors\fR file.
290 SAY strings must be enclosed in single or double quotes. If carriage return and
291 line feed are required for the output, you must explicitly add them to your
292 string.
295 The SAY string can provide progress messages to users even with "ECHO OFF." For
296 example, add a line similar to the following to the script:
298 .in +2
300 ABORT BUSY
301 ECHO OFF
302 SAY "Dialing your ISP...\en"
303 \&'' ATDT5551212
304 TIMEOUT 120
305 SAY "Waiting up to 2 minutes for connection ..."
306 CONNECT ''
307 SAY "Connected, now logging in ...\en"
308 ogin: account
309 ssword: pass
310 $ \ec
311 SAY "Logged in OK ... \en"
313 .in -2
317 This sequence hides script detail while presenting the SAY string to the user.
318 In this case, you will see:
320 .in +2
322 Dialing your ISP...
323 Waiting up to 2 minutes for connection...Connected, now logging in...
324 Logged in OK ...
326 .in -2
328 .SS "Report"
330 REPORT is similar to the ABORT string. With REPORT, however, strings and all
331 characters to the next control character (such as a carriage return), are
332 written to the report file.
335 REPORT strings can be used to isolate a modem's transmission rate from its
336 CONNECT string and return the value to the \fBchat\fR user. Analysis of the
337 REPORT string logic occurs in conjunction with other string processing, such as
338 looking for the expect string. It's possible to use the same string for a
339 REPORT and ABORT sequence, but probably not useful.
342 Report strings may be specified in the script using the REPORT sequence. For
343 example:
345 .in +2
347 REPORT CONNECT
348 ABORT BUSY
349 ATDT5551212 CONNECT
350 ogin: account
352 .in -2
356 The above sequence expects nothing, then sends the string ATDT5551212 to dial
357 the telephone. The expected string is CONNECT. If CONNECT is received, the
358 remainder of the script is executed. In addition, the program writes the string
359 CONNECT to the report file (specified by \fB-r\fR) in addition to any
360 characters that follow.
361 .SS "Clr_Report"
363 CLR_REPORT clears previously set REPORT strings. REPORT strings are kept in an
364 array of a pre-determined size; CLR_REPORT reclaims the space for cleared
365 entries so that new strings can use that space.
366 .SS "Echo"
368 ECHO determines if modem output is echoed to \fBstderr\fR. This option may be
369 set with the \fB-e\fR option, but can also be controlled by the ECHO keyword.
370 The "expect-send" pair  ECHO ON enables echoing, and ECHO OFF disables it. With
371 ECHO, you can select which parts of the conversation should be visible. In the
372 following script:
374 .in +2
376 ABORT   'BUSY'
377 ABORT   'NO CARRIER'
378 ""    AT&F
379 OK\er\en  ATD1234567
380 \er\en    \ec
381 ECHO    ON
382 CONNECT \ec
383 ogin:   account
385 .in -2
389 All output resulting from modem configuration and dialing is not visible, but
390 output is echoed beginning with the CONNECT (or BUSY) message.
391 .SS "Hangup"
393 The HANGUP option determines if a modem hangup is considered as an error.
394 HANGUP is useful for dialing systems that hang up and call your system back.
395 HANGUP can be ON or OFF. When HANGUP is set to OFF and the modem hangs up (for
396 example, following the first stage of logging in to a callback system),
397 \fBchat\fR continues running the script (for example, waiting for the incoming
398 call and second stage login prompt). When the incoming call is connected, use
399 the HANGUP ON string to reinstall normal hang up signal behavior. An example of
400 a simple script follows:
402 .in +2
404 ABORT   'BUSY'
405  ""  AT&F
406  OK\er\en  ATD1234567
407  \er\en    \ec
408  CONNECT \ec
409  'Callback login:' call_back_ID
410  HANGUP OFF
411  ABORT "Bad Login"
412  'Callback Password:' Call_back_password
413  TIMEOUT 120
414  CONNECT \ec
415  HANGUP ON
416  ABORT "NO CARRIER"
417  ogin:--BREAK--ogin: real_account
419 .in -2
421 .SS "Timeout"
423 The initial timeout value is 45 seconds. Use the \fB-t\fR parameter to change
424 the initial timeout value.
427 To change the timeout value for the next expect string, the following example
428 can be used:
430 .in +2
432 \&''"AT&F
433  OK ATDT5551212
434  CONNECT \ec
435  TIMEOUT 10
436  ogin:--ogin: username
437  TIMEOUT 5
438  assword: hello2u2
440 .in -2
444 The example changes the timeout to ten seconds when it expects the login:
445 prompt. The timeout is changed to five seconds when it looks for the password
446 prompt.
449 Once changed, the timeout value remains in effect until it is changed again.
450 .SS " EOT"
452 The EOT special reply string instructs the \fBchat\fR program to send an EOT
453 character to the remote. This is equivalent to using ^D\ec as the reply string.
454 The EOT string normally indicates the end-of-file character sequence. A return
455 character is not sent following the EOT. The EOT sequence can embedded into the
456 send string using the sequence ^D.
457 .SS " BREAK"
459 The BREAK special reply string sends a break condition. The break is a special
460 transmitter signal. Many UNIX systems handle break by cycling through available
461 bit rates, and sending break is often needed when the remote system does not
462 support autobaud. BREAK is equivalent to using \eK\ec as the reply string.
463 You embed the break sequence into the send string using the \eK sequence.
464 .SS "Escape Sequences"
466 Expect and reply strings can contain escape sequences. Reply strings accept all
467 escape sequences, while expect strings accept most sequences. A list of escape
468 sequences is presented below. Sequences that are not accepted by expect strings
469 are indicated.
471 .ne 2
473 \fB\fB\&''\fR \fR
475 .RS 10n
476 Expects or sends a null string. If you send a null string, \fBchat\fR sends
477 the return character.  If you expect a null string, \fBchat\fR proceeds to the
478 reply string without waiting.  This sequence can be a pair of apostrophes or
479 quote mark characters.
483 .ne 2
485 \fB\fB\eb\fR \fR
487 .RS 10n
488 Represents a backspace character.
492 .ne 2
494 \fB\fB\ec\fR \fR
496 .RS 10n
497 Suppresses the newline at the end of the reply string. This is the only method
498 to send a string without a trailing return character. This sequence must be at
499 the end of the send string. For example, the sequence hello\ec will simply send
500 the characters h, e, l, l, o. (Not valid  in expect.)
504 .ne 2
506 \fB\fB\ed\fR \fR
508 .RS 10n
509 Delay for one second. The program uses \fBsleep\fR(1) which delays to a maximum
510 of one second.  (Not valid  in expect.)
514 .ne 2
516 \fB\fB\eK\fR \fR
518 .RS 10n
519 Insert a BREAK.  (Not valid  in expect.)
523 .ne 2
525 \fB\fB\en\fR \fR
527 .RS 10n
528 Send a newline or linefeed character.
532 .ne 2
534 \fB\fB\eN\fR \fR
536 .RS 10n
537 Send a null character. The same sequence may be represented by \e0.  (Not valid
538 in expect.)
542 .ne 2
544 \fB\fB\ep\fR \fR
546 .RS 10n
547 Pause for 1/10th of a second.  (Not valid  in expect.)
551 .ne 2
553 \fB\fB\eq\fR \fR
555 .RS 10n
556 Suppress writing the string to syslog.  The string ?????? is written to the log
557 in its place. (Not valid  in expect.)
561 .ne 2
563 \fB\fB\er\fR \fR
565 .RS 10n
566 Send or expect a carriage return.
570 .ne 2
572 \fB\fB\es\fR \fR
574 .RS 10n
575 Represents a space character in the string. Can be used when it is not
576 desirable to quote the strings which contains spaces. The sequence 'HI\ TIM'
577 and HI\esTIM are the same.
581 .ne 2
583 \fB\fB\et\fR \fR
585 .RS 10n
586 Send or expect a tab character.
590 .ne 2
592 \fB\fB\eT\fR \fR
594 .RS 10n
595 Send the phone number string as specified with the \fB-T\fR option.  (Not valid
596 in expect.)
600 .ne 2
602 \fB\fB\eU\fR \fR
604 .RS 10n
605 Send the phone number 2 string as specified with the \fB-U\fR option. (Not
606 valid  in expect.)
610 .ne 2
612 \fB\fB\e\e\fR \fR
614 .RS 10n
615 Send or expect a backslash character.
619 .ne 2
621 \fB\fB\eddd\fR \fR
623 .RS 10n
624 Collapse the octal digits (ddd) into a single ASCII character and send that
625 character. (\e000 is not valid in an expect string.)
629 .ne 2
631 \fB\fB^C\fR \fR
633 .RS 10n
634 Substitute the sequence with the control character represented by C. For
635 example, the character DC1 (17) is shown as ^Q. (Some characters are not valid
636 in expect.)
639 .SH ENVIRONMENT VARIABLES
641 Environment variables are available within \fBchat\fR scripts if the \fB-E\fR
642 option is specified on the command line. The metacharacter \fB$\fR introduces
643 the name of the environment variable to substitute. If the substitution fails
644 because the requested environment variable is not set, nothing is replaced for
645 the variable.
646 .SH EXIT STATUS
648 The \fBchat\fR program terminates with the following completion codes:
650 .ne 2
652 \fB\fB0\fR \fR
654 .RS 10n
655 Normal program termination. Indicates that the script was executed without
656 error to normal conclusion.
660 .ne 2
662 \fB\fB1\fR \fR
664 .RS 10n
665 One or more of the parameters are invalid or an expect string was too large for
666 the internal buffers. Indicates that the program was not properly executed.
670 .ne 2
672 \fB\fB2\fR \fR
674 .RS 10n
675 An error occurred during the execution of the program. This may be due to a
676 read or write operation failing or \fBchat\fR receiving a signal such as
677 SIGINT.
681 .ne 2
683 \fB\fB3\fR \fR
685 .RS 10n
686 A timeout event occurred when there was an expect string without having a
687 "-subsend" string. This indicates that you may not have programmed the script
688 correctly for the condition or that an unexpected event occurred and the
689 expected string could not be found.
693 .ne 2
695 \fB\fB4\fR \fR
697 .RS 10n
698 The first string marked as an ABORT condition occurred.
702 .ne 2
704 \fB\fB5\fR \fR
706 .RS 10n
707 The second string marked as an ABORT condition occurred.
711 .ne 2
713 \fB\fB6\fR \fR
715 .RS 10n
716 The third string marked as an ABORT  condition occurred.
720 .ne 2
722 \fB\fB7\fR \fR
724 .RS 10n
725 The fourth string marked as an ABORT condition occurred.
729 .ne 2
731 \fB\fB\&...\fR \fR
733 .RS 10n
734 The other termination codes are also strings marked as an ABORT condition.
739 To determine which event terminated the script, use the termination code. It is
740 possible to decide if the string "BUSY" was received from the modem versus "NO
741 DIALTONE." While the first event may be retried, the second probably will not
742 succeed during a retry.
743 .SH ATTRIBUTES
745 See \fBattributes\fR(5)  for descriptions of the following attributes:
750 box;
751 c | c
752 l | l .
753 ATTRIBUTE TYPE  ATTRIBUTE VALUE
755 Interface Stability     Evolving
758 .SH SEE ALSO
760 \fBsleep\fR(1), \fBpppd\fR(8), \fBsyslog\fR(3C), \fBattributes\fR(5)