1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
|
'\" te
.\" This manual page is based on documentation obtained from Karl Fox.
.\" Portions Copyright (C) 2008, Sun Microsystems, Inc. All Rights Reserved
.\" 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.
.\" 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.
.\" 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]
.TH CHAT 1M "August 29, 2021"
.SH NAME
chat \- automated conversational exchange tool
.SH SYNOPSIS
.nf
\fBchat\fR [\fIoptions\fR] \fIscript\fR
.fi
.SH DESCRIPTION
The \fBchat\fR program implements a conversational text-based exchange between
the computer and any serial device, including (but not limited to) a modem, an
ISDN TA, and the remote peer itself, establishing a connection between the
Point-To-Point Protocol daemon (\fBpppd\fR) and the remote \fBpppd\fR process.
.SH OPTIONS
The \fBchat\fR command supports the following options:
.sp
.ne 2
.na
\fB\fB-f\fR \fI<chat file>\fR\fR
.ad
.RS 23n
Read the \fBchat\fR script from the \fBchat\fR file. This option is mutually
exclusive with the \fBchat\fR script parameters. You must have \fBread\fR
access to use the file. Multiple lines are permitted in the file. Use the space
or horizontal tab characters to separate the strings.
.RE
.sp
.ne 2
.na
\fB\fB-t\fR \fB\fI<timeout>\fR\fR \fR
.ad
.RS 23n
Set the timeout for the expected string to be received. If the string is not
received within the time limit, the reply string is not sent. If specified,
a 'subexpect' (alternate reply) string can be sent. Otherwise, if no alternate
reply strings remain, the \fBchat\fR script fails. A failed script will cause
the \fBchat\fR program to terminate with a non-zero error code.
.RE
.sp
.ne 2
.na
\fB\fB-r\fR \fB\fI<report file> \fR\fR \fR
.ad
.RS 23n
Set the file for output of the report strings. If you use the keyword
\fBREPORT\fR, the resulting strings are written to this file. If the \fB-r\fR
option is not used and you use the \fBREPORT\fR keyword, the \fBstderr\fR file
is used for the report strings.
.RE
.sp
.ne 2
.na
\fB\fB-e\fR \fR
.ad
.RS 23n
Start with the echo option turned on. You turn echo on or off at specific
points in the \fBchat\fR script using the \fBECHO\fR keyword. When echoing is
enabled, all output from the modem is echoed to \fBstderr\fR.
.RE
.sp
.ne 2
.na
\fB\fB-E\fR \fR
.ad
.RS 23n
Enables environment variable substitution within \fBchat\fR scripts using the
standard \fI$xxx\fR syntax.
.RE
.sp
.ne 2
.na
\fB\fB-v\fR \fR
.ad
.RS 23n
Request that the \fBchat\fR script execute in a verbose mode. The \fBchat\fR
program logs the execution state of the \fBchat\fR script as well as all text
received from the modem and output strings sent to the modem. The default is to
log through \fBsyslog\fR(3C) with facility \fBlocal\fR2; the logging method is
alterable using the \fB-S\fR and \fB-s\fR options.
.RE
.sp
.ne 2
.na
\fB\fB-V\fR \fR
.ad
.RS 23n
Request that the \fBchat\fR script be executed in a \fBstderr\fR verbose mode.
The \fBchat\fR program logs all text received from the modem and output strings
sent to the modem to \fBstderr\fR. \fBstderr\fR is usually the local console at
the station running the \fBchat\fR or \fBpppd\fR program.
.RE
.sp
.ne 2
.na
\fB\fB-s\fR\fR
.ad
.RS 23n
Use \fBstderr\fR. Log messages from \fB-v\fR and error messages are sent to
\fBstderr\fR.
.RE
.sp
.ne 2
.na
\fB\fB-S\fR\fR
.ad
.RS 23n
Do not use syslog. By default, error messages are set to syslog. This option
prevents log messages from \fB-v\fR and error messages from being sent to
syslog.
.RE
.sp
.ne 2
.na
\fB\fB-T\fR \fB\fI<phone number>\fR\fR\fR
.ad
.RS 23n
Pass in an arbitrary string (usually a telephone number) that will be
substituted for the \fB\eT\fR substitution metacharacter in a send string.
.RE
.sp
.ne 2
.na
\fB\fB-U\fR \fB\fI<phone number 2>\fR\fR\fR
.ad
.RS 23n
Pass in a second string (usually a telephone number) that will be substituted
for the \fB\eU\fR substitution metacharacter in a send string. This is useful
when dialing an ISDN terminal adapter that requires two numbers.
.RE
.sp
.ne 2
.na
\fB\fBscript\fR \fR
.ad
.RS 23n
If the script is not specified in a file with the \fB-f\fR option, the script
is included as parameters to the \fBchat\fR program.
.RE
.SH EXTENDED DESCRIPTION
.SS "Chat Script"
The \fBchat\fR script defines communications. A script consists of one or more
"expect-send" pairs of strings separated by spaces, with an optional
"subexpect-subsend" string pair, separated by a dash (as in the following
example:)
.sp
.LP
ogin:-BREAK-ogin: ppp ssword: hello2u2
.sp
.LP
The example indicates that the \fBchat\fR program should expect the string
"ogin:". If it fails to receive a login prompt within the time interval
allotted, it sends a break sequence to the remote and then expects the string
"ogin:". If the first "ogin:" is received, the break sequence is not generated.
.sp
.LP
Upon receiving the login prompt, the \fBchat\fR program sends the string "ppp"
and then expects the prompt "ssword:". When the password prompt is received, it
sends the password hello2u2.
.sp
.LP
A carriage return is normally sent following the reply string. It is not
expected in the "expect" string unless it is specifically requested by using
the \fB\er\fR character sequence.
.sp
.LP
The expect sequence should contain only what is needed to identify the received
data. Because it's stored on a disk file, it should not contain variable
information. Generally it is not acceptable to look for time strings, network
identification strings, or other variable pieces of data as an expect string.
.sp
.LP
To correct for characters that are corrupted during the initial sequence, look
for the string "ogin:" rather than "login:". The leading "l" character may be
received in error, creating problems in finding the string. For this reason,
scripts look for "ogin:" rather than "login:" and "ssword:" rather than
"password:".
.sp
.LP
An example of a simple script follows:
.sp
.in +2
.nf
ogin: ppp ssword: hello2u2
.fi
.in -2
.sp
.LP
The example can be interpreted as: expect ogin:, send ppp, expect ...ssword:,
send hello2u2.
.sp
.LP
When login to a remote peer is necessary, simple scripts are rare. At minimum,
you should include sub-expect sequences in case the original string is not
received. For example, consider the following script:
.sp
.in +2
.nf
ogin:--ogin: ppp ssword: hello2u2
.fi
.in -2
.sp
.LP
This script is more effective than the simple one used earlier. The string
looks for the same login prompt; however, if one is not received, a single
return sequence is sent and then the script looks for login: again. If line
noise obscures the first login prompt, send the empty line to generate a login
prompt again.
.SS "Comments"
Comments can be embedded in the \fBchat\fR script. Comment lines are ignored by
the chat program. A comment starts with the hash ("#") character in column one.
If a \fB#\fR character is expected as the first character of the expect
sequence, quote the expect string. If you want to wait for a prompt that starts
with a \fB#\fR character, write something like this:
.sp
.in +2
.nf
# Now wait for the prompt and send logout string
\&'# ' logout
.fi
.in -2
.SS "Sending Data From A File"
If the string to send begins with an at sign ("@"), the remainder of the string
is interpreted as the name of the file that contains the string. If the last
character of the data read is a newline, it is removed. The file can be a named
pipe (or fifo) instead of a regular file. This enables \fBchat\fR to
communicate with another program, for example, a program to prompt the user and
receive a password typed in.
.SS "Abort "
Many modems report the status of a call as a string. These status strings are
often "CONNECTED" or "NO CARRIER" or "BUSY." If the modem fails to connect to
the remote, you can terminate the script. Abort strings may be specified in the
script using the ABORT sequence. For example:
.sp
.in +2
.nf
ABORT BUSY ABORT 'NO CARRIER' '' ATZ OK ATDT5551212 CONNECT
.fi
.in -2
.sp
.LP
This sequence expects nothing and sends the string ATZ. The expected response
is the string OK. When OK is received, the string ATDT5551212 dials the
telephone. The expected string is CONNECT. If CONNECT is received, the
remainder of the script is executed. When the modem finds a busy telephone, it
sends the string BUSY, causing the string to match the abort character
sequence. The script fails because it found a match to the abort string. If the
NO CARRIER string is received, it aborts for the same reason.
.SS "Clr_Abort "
The CLR_ABORT sequence clears previously set ABORT strings. ABORT strings are
kept in an array of a pre-determined size; CLR_ABORT reclaims the space for
cleared entries, enabling new strings to use that space.
.SS "Say "
The SAY string enables the script to send strings to a user at a terminal via
standard error. If \fBchat\fR is being run by \fBpppd\fR and \fBpppd\fR is
running as a daemon (detached from its controlling terminal), standard error is
normally redirected to the \fB/etc/ppp/connect-errors\fR file.
.sp
.LP
SAY strings must be enclosed in single or double quotes. If carriage return and
line feed are required for the output, you must explicitly add them to your
string.
.sp
.LP
The SAY string can provide progress messages to users even with "ECHO OFF." For
example, add a line similar to the following to the script:
.sp
.in +2
.nf
ABORT BUSY
ECHO OFF
SAY "Dialing your ISP...\en"
\&'' ATDT5551212
TIMEOUT 120
SAY "Waiting up to 2 minutes for connection ..."
CONNECT ''
SAY "Connected, now logging in ...\en"
ogin: account
ssword: pass
$ \ec
SAY "Logged in OK ... \en"
.fi
.in -2
.sp
.LP
This sequence hides script detail while presenting the SAY string to the user.
In this case, you will see:
.sp
.in +2
.nf
Dialing your ISP...
Waiting up to 2 minutes for connection...Connected, now logging in...
Logged in OK ...
.fi
.in -2
.SS "Report"
REPORT is similar to the ABORT string. With REPORT, however, strings and all
characters to the next control character (such as a carriage return), are
written to the report file.
.sp
.LP
REPORT strings can be used to isolate a modem's transmission rate from its
CONNECT string and return the value to the \fBchat\fR user. Analysis of the
REPORT string logic occurs in conjunction with other string processing, such as
looking for the expect string. It's possible to use the same string for a
REPORT and ABORT sequence, but probably not useful.
.sp
.LP
Report strings may be specified in the script using the REPORT sequence. For
example:
.sp
.in +2
.nf
REPORT CONNECT
ABORT BUSY
ATDT5551212 CONNECT
ogin: account
.fi
.in -2
.sp
.LP
The above sequence expects nothing, then sends the string ATDT5551212 to dial
the telephone. The expected string is CONNECT. If CONNECT is received, the
remainder of the script is executed. In addition, the program writes the string
CONNECT to the report file (specified by \fB-r\fR) in addition to any
characters that follow.
.SS "Clr_Report"
CLR_REPORT clears previously set REPORT strings. REPORT strings are kept in an
array of a pre-determined size; CLR_REPORT reclaims the space for cleared
entries so that new strings can use that space.
.SS "Echo"
ECHO determines if modem output is echoed to \fBstderr\fR. This option may be
set with the \fB-e\fR option, but can also be controlled by the ECHO keyword.
The "expect-send" pair ECHO ON enables echoing, and ECHO OFF disables it. With
ECHO, you can select which parts of the conversation should be visible. In the
following script:
.sp
.in +2
.nf
ABORT 'BUSY'
ABORT 'NO CARRIER'
"" AT&F
OK\er\en ATD1234567
\er\en \ec
ECHO ON
CONNECT \ec
ogin: account
.fi
.in -2
.sp
.LP
All output resulting from modem configuration and dialing is not visible, but
output is echoed beginning with the CONNECT (or BUSY) message.
.SS "Hangup"
The HANGUP option determines if a modem hangup is considered as an error.
HANGUP is useful for dialing systems that hang up and call your system back.
HANGUP can be ON or OFF. When HANGUP is set to OFF and the modem hangs up (for
example, following the first stage of logging in to a callback system),
\fBchat\fR continues running the script (for example, waiting for the incoming
call and second stage login prompt). When the incoming call is connected, use
the HANGUP ON string to reinstall normal hang up signal behavior. An example of
a simple script follows:
.sp
.in +2
.nf
ABORT 'BUSY'
"" AT&F
OK\er\en ATD1234567
\er\en \ec
CONNECT \ec
'Callback login:' call_back_ID
HANGUP OFF
ABORT "Bad Login"
'Callback Password:' Call_back_password
TIMEOUT 120
CONNECT \ec
HANGUP ON
ABORT "NO CARRIER"
ogin:--BREAK--ogin: real_account
.fi
.in -2
.SS "Timeout"
The initial timeout value is 45 seconds. Use the \fB-t\fR parameter to change
the initial timeout value.
.sp
.LP
To change the timeout value for the next expect string, the following example
can be used:
.sp
.in +2
.nf
\&''"AT&F
OK ATDT5551212
CONNECT \ec
TIMEOUT 10
ogin:--ogin: username
TIMEOUT 5
assword: hello2u2
.fi
.in -2
.sp
.LP
The example changes the timeout to ten seconds when it expects the login:
prompt. The timeout is changed to five seconds when it looks for the password
prompt.
.sp
.LP
Once changed, the timeout value remains in effect until it is changed again.
.SS " EOT"
The EOT special reply string instructs the \fBchat\fR program to send an EOT
character to the remote. This is equivalent to using ^D\ec as the reply string.
The EOT string normally indicates the end-of-file character sequence. A return
character is not sent following the EOT. The EOT sequence can embedded into the
send string using the sequence ^D.
.SS " BREAK"
The BREAK special reply string sends a break condition. The break is a special
transmitter signal. Many UNIX systems handle break by cycling through available
bit rates, and sending break is often needed when the remote system does not
support autobaud. BREAK is equivalent to using \eK\ec as the reply string.
You embed the break sequence into the send string using the \eK sequence.
.SS "Escape Sequences"
Expect and reply strings can contain escape sequences. Reply strings accept all
escape sequences, while expect strings accept most sequences. A list of escape
sequences is presented below. Sequences that are not accepted by expect strings
are indicated.
.sp
.ne 2
.na
\fB\fB\&''\fR \fR
.ad
.RS 10n
Expects or sends a null string. If you send a null string, \fBchat\fR sends
the return character. If you expect a null string, \fBchat\fR proceeds to the
reply string without waiting. This sequence can be a pair of apostrophes or
quote mark characters.
.RE
.sp
.ne 2
.na
\fB\fB\eb\fR \fR
.ad
.RS 10n
Represents a backspace character.
.RE
.sp
.ne 2
.na
\fB\fB\ec\fR \fR
.ad
.RS 10n
Suppresses the newline at the end of the reply string. This is the only method
to send a string without a trailing return character. This sequence must be at
the end of the send string. For example, the sequence hello\ec will simply send
the characters h, e, l, l, o. (Not valid in expect.)
.RE
.sp
.ne 2
.na
\fB\fB\ed\fR \fR
.ad
.RS 10n
Delay for one second. The program uses \fBsleep\fR(1) which delays to a maximum
of one second. (Not valid in expect.)
.RE
.sp
.ne 2
.na
\fB\fB\eK\fR \fR
.ad
.RS 10n
Insert a BREAK. (Not valid in expect.)
.RE
.sp
.ne 2
.na
\fB\fB\en\fR \fR
.ad
.RS 10n
Send a newline or linefeed character.
.RE
.sp
.ne 2
.na
\fB\fB\eN\fR \fR
.ad
.RS 10n
Send a null character. The same sequence may be represented by \e0. (Not valid
in expect.)
.RE
.sp
.ne 2
.na
\fB\fB\ep\fR \fR
.ad
.RS 10n
Pause for 1/10th of a second. (Not valid in expect.)
.RE
.sp
.ne 2
.na
\fB\fB\eq\fR \fR
.ad
.RS 10n
Suppress writing the string to syslog. The string ?????? is written to the log
in its place. (Not valid in expect.)
.RE
.sp
.ne 2
.na
\fB\fB\er\fR \fR
.ad
.RS 10n
Send or expect a carriage return.
.RE
.sp
.ne 2
.na
\fB\fB\es\fR \fR
.ad
.RS 10n
Represents a space character in the string. Can be used when it is not
desirable to quote the strings which contains spaces. The sequence 'HI\ TIM'
and HI\esTIM are the same.
.RE
.sp
.ne 2
.na
\fB\fB\et\fR \fR
.ad
.RS 10n
Send or expect a tab character.
.RE
.sp
.ne 2
.na
\fB\fB\eT\fR \fR
.ad
.RS 10n
Send the phone number string as specified with the \fB-T\fR option. (Not valid
in expect.)
.RE
.sp
.ne 2
.na
\fB\fB\eU\fR \fR
.ad
.RS 10n
Send the phone number 2 string as specified with the \fB-U\fR option. (Not
valid in expect.)
.RE
.sp
.ne 2
.na
\fB\fB\e\e\fR \fR
.ad
.RS 10n
Send or expect a backslash character.
.RE
.sp
.ne 2
.na
\fB\fB\eddd\fR \fR
.ad
.RS 10n
Collapse the octal digits (ddd) into a single ASCII character and send that
character. (\e000 is not valid in an expect string.)
.RE
.sp
.ne 2
.na
\fB\fB^C\fR \fR
.ad
.RS 10n
Substitute the sequence with the control character represented by C. For
example, the character DC1 (17) is shown as ^Q. (Some characters are not valid
in expect.)
.RE
.SH ENVIRONMENT VARIABLES
Environment variables are available within \fBchat\fR scripts if the \fB-E\fR
option is specified on the command line. The metacharacter \fB$\fR introduces
the name of the environment variable to substitute. If the substitution fails
because the requested environment variable is not set, nothing is replaced for
the variable.
.SH EXIT STATUS
The \fBchat\fR program terminates with the following completion codes:
.sp
.ne 2
.na
\fB\fB0\fR \fR
.ad
.RS 10n
Normal program termination. Indicates that the script was executed without
error to normal conclusion.
.RE
.sp
.ne 2
.na
\fB\fB1\fR \fR
.ad
.RS 10n
One or more of the parameters are invalid or an expect string was too large for
the internal buffers. Indicates that the program was not properly executed.
.RE
.sp
.ne 2
.na
\fB\fB2\fR \fR
.ad
.RS 10n
An error occurred during the execution of the program. This may be due to a
read or write operation failing or \fBchat\fR receiving a signal such as
SIGINT.
.RE
.sp
.ne 2
.na
\fB\fB3\fR \fR
.ad
.RS 10n
A timeout event occurred when there was an expect string without having a
"-subsend" string. This indicates that you may not have programmed the script
correctly for the condition or that an unexpected event occurred and the
expected string could not be found.
.RE
.sp
.ne 2
.na
\fB\fB4\fR \fR
.ad
.RS 10n
The first string marked as an ABORT condition occurred.
.RE
.sp
.ne 2
.na
\fB\fB5\fR \fR
.ad
.RS 10n
The second string marked as an ABORT condition occurred.
.RE
.sp
.ne 2
.na
\fB\fB6\fR \fR
.ad
.RS 10n
The third string marked as an ABORT condition occurred.
.RE
.sp
.ne 2
.na
\fB\fB7\fR \fR
.ad
.RS 10n
The fourth string marked as an ABORT condition occurred.
.RE
.sp
.ne 2
.na
\fB\fB\&...\fR \fR
.ad
.RS 10n
The other termination codes are also strings marked as an ABORT condition.
.RE
.sp
.LP
To determine which event terminated the script, use the termination code. It is
possible to decide if the string "BUSY" was received from the modem versus "NO
DIALTONE." While the first event may be retried, the second probably will not
succeed during a retry.
.SH ATTRIBUTES
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE ATTRIBUTE VALUE
_
Interface Stability Evolving
.TE
.SH SEE ALSO
\fBsleep\fR(1), \fBuucp\fR(1C), \fBpppd\fR(1M), \fBuucico\fR(1M),
\fBsyslog\fR(3C), \fBattributes\fR(5)
.sp
.LP
Additional information on \fBchat\fR scripts are available with UUCP
documentation. The \fBchat\fR script format was taken from scripts used by the
\fBuucico\fR program.
|