xref: /freebsd/usr.bin/chat/chat.8 (revision b2c76c41be32f904179efed29c0ca04d53f3996c)
1c664bd46SJoel Dahl.Dd September 10, 2012
2c664bd46SJoel Dahl.Dt CHAT 8
3c664bd46SJoel Dahl.Os
4c664bd46SJoel Dahl.Sh NAME
5c664bd46SJoel Dahl.Nm chat
6c664bd46SJoel Dahl.Nd Automated conversational script with a modem
7c664bd46SJoel Dahl.Sh SYNOPSIS
8c664bd46SJoel Dahl.Nm
9c664bd46SJoel Dahl.Op Fl eSsVv
10c664bd46SJoel Dahl.Op Fl f Ar chat-file
11c664bd46SJoel Dahl.Op Fl r Ar report-file
12c664bd46SJoel Dahl.Op Fl T Ar phone-number
13c664bd46SJoel Dahl.Op Fl t Ar timeout
14c664bd46SJoel Dahl.Op Fl U Ar phone-number2
15c664bd46SJoel Dahl.Op Ar script
16c664bd46SJoel Dahl.Sh DESCRIPTION
17c664bd46SJoel DahlThe
18c664bd46SJoel Dahl.Nm
19c664bd46SJoel Dahlprogram defines a conversational exchange between the
2087faa07bSSheldon Hearncomputer and the modem.
2187faa07bSSheldon HearnIts primary purpose is to establish the
22c664bd46SJoel Dahlconnection between the Point-to-Point Protocol Daemon
23c664bd46SJoel Dahl.Pq pppd
24c664bd46SJoel Dahland the remote's pppd process.
25c664bd46SJoel Dahl.Sh OPTIONS
26c664bd46SJoel Dahl.Bl -tag -width indent
27c664bd46SJoel Dahl.It Fl e
28c664bd46SJoel DahlStart with the echo option turned on.
29c664bd46SJoel DahlEchoing may also be turned on
30c664bd46SJoel Dahlor off at specific points in the chat script by using the ECHO
31c664bd46SJoel Dahlkeyword.
32c664bd46SJoel DahlWhen echoing is enabled, all output from the modem is echoed
33c664bd46SJoel Dahlto
34c664bd46SJoel Dahl.Em stderr .
35c664bd46SJoel Dahl.It Fl f Ar chat-file
36c664bd46SJoel DahlRead the chat script from the chat file.
3787faa07bSSheldon HearnThe use of this option
3887faa07bSSheldon Hearnis mutually exclusive with the chat script parameters.
3987faa07bSSheldon HearnThe user must
4087faa07bSSheldon Hearnhave read access to the file.
41c664bd46SJoel DahlMultiple lines are permitted in the file.
4287faa07bSSheldon HearnSpace or horizontal tab characters should be used to separate
439b1aec48SLars Fredriksenthe strings.
44c664bd46SJoel Dahl.It Fl r Ar report-file
45c664bd46SJoel DahlSet the file for output of the report strings.
46c664bd46SJoel DahlIf you use the keyword
47c664bd46SJoel Dahl.Dv REPORT ,
48c664bd46SJoel Dahlthe resulting strings are written to this file.
49c664bd46SJoel DahlIf this
50c664bd46SJoel Dahloption is not used and you still use
51c664bd46SJoel Dahl.Dv REPORT
52c664bd46SJoel Dahlkeywords, the
53c664bd46SJoel Dahl.Pa stderr
54c664bd46SJoel Dahlfile is used for the report strings.
55c664bd46SJoel Dahl.It Fl S
56c664bd46SJoel DahlDo not use
57c664bd46SJoel Dahl.Xr syslog 3 .
58c664bd46SJoel DahlBy default, error messages are sent to
59c664bd46SJoel Dahl.Xr syslog 3 .
60c664bd46SJoel DahlThe use of
61c664bd46SJoel Dahl.Fl S
62c664bd46SJoel Dahlwill prevent both log messages from
63c664bd46SJoel Dahl.Fl v
64c664bd46SJoel Dahland error messages from being sent to
65c664bd46SJoel Dahl.Xr syslog 3 .
66c664bd46SJoel Dahl.It Fl s
67c664bd46SJoel DahlUse
68c664bd46SJoel Dahl.Em stderr .
69c664bd46SJoel DahlAll log messages from
70c664bd46SJoel Dahl.Fl v
71c664bd46SJoel Dahland all error messages will be
72c664bd46SJoel Dahlsent to
73c664bd46SJoel Dahl.Em stderr .
74c664bd46SJoel Dahl.It Fl T Ar phone-number
75c664bd46SJoel DahlPass in an arbitrary string, usually a phone number, that will be
76c664bd46SJoel Dahlsubstituted for the \\T substitution metacharacter in a send string.
77c664bd46SJoel Dahl.It Fl t Ar timeout
7887faa07bSSheldon HearnSet the timeout for the expected string to be received.
7987faa07bSSheldon HearnIf the string
809b1aec48SLars Fredriksenis not received within the time limit then the reply string is not
8187faa07bSSheldon Hearnsent.
8287faa07bSSheldon HearnAn alternate reply may be sent or the script will fail if there
8387faa07bSSheldon Hearnis no alternate reply string.
8487faa07bSSheldon HearnA failed script will cause the
85c664bd46SJoel Dahl.Nm
86c664bd46SJoel Dahlprogram to terminate with a non-zero error code.
87c664bd46SJoel Dahl.It Fl U Ar phone-number2
8801c855caSPeter WemmPass in a second string, usually a phone number, that will be
8901c855caSPeter Wemmsubstituted for the \\U substitution metacharacter in a send string.
9001c855caSPeter WemmThis is useful when dialing an ISDN terminal adapter that requires two
9101c855caSPeter Wemmnumbers.
92c664bd46SJoel Dahl.It Fl V
93c664bd46SJoel DahlRequest that the
94c664bd46SJoel Dahl.Nm
95c664bd46SJoel Dahlscript be executed in a
96c664bd46SJoel Dahl.Em stderr
97c664bd46SJoel Dahlverbose mode.
98c664bd46SJoel DahlThe
99c664bd46SJoel Dahl.Nm
100c664bd46SJoel Dahlprogram will then log all text received from the
101c664bd46SJoel Dahlmodem and the output strings sent to the modem to the stderr device.
102c664bd46SJoel DahlThis
103c664bd46SJoel Dahldevice is usually the local console at the station running the chat or
104c664bd46SJoel Dahlpppd program.
105c664bd46SJoel Dahl.It Fl v
106c664bd46SJoel DahlRequest that the
107c664bd46SJoel Dahl.Nm
108c664bd46SJoel Dahlscript be executed in a verbose mode.
109c664bd46SJoel DahlThe
110c664bd46SJoel Dahl.Nm
111c664bd46SJoel Dahlprogram will then log the execution state of the chat
112c664bd46SJoel Dahlscript as well as all text received from the modem and the output
113c664bd46SJoel Dahlstrings sent to the modem.
114c664bd46SJoel DahlThe default is to log through
115c664bd46SJoel Dahl.Xr syslog 3 ;
116c664bd46SJoel Dahlthe logging method may be altered with the
117c664bd46SJoel Dahl.Fl S
118c664bd46SJoel Dahland
119c664bd46SJoel Dahl.Fl s
120c664bd46SJoel Dahlflags.
121c664bd46SJoel DahlLogging is done to the
122c664bd46SJoel Dahl.Em local2
123c664bd46SJoel Dahlfacility at level
124c664bd46SJoel Dahl.Em info
125c664bd46SJoel Dahlfor verbose tracing and level
126c664bd46SJoel Dahl.Em err
127c664bd46SJoel Dahlfor some errors.
128c664bd46SJoel Dahl.El
129c664bd46SJoel Dahl.Sh CHAT SCRIPT
130c664bd46SJoel DahlThe
131c664bd46SJoel Dahl.Nm
132c664bd46SJoel Dahlscript defines the communications.
1339b1aec48SLars FredriksenA script consists of one or more "expect-send" pairs of strings,
1349b1aec48SLars Fredriksenseparated by spaces, with an optional "subexpect-subsend" string pair,
1359b1aec48SLars Fredriksenseparated by a dash as in the following example:
136c664bd46SJoel Dahl.Pp
137c664bd46SJoel Dahl.D1 ogin:-BREAK-ogin: ppp ssword: hello2u2
138c664bd46SJoel Dahl.Pp
139c664bd46SJoel DahlThis line indicates that the
140c664bd46SJoel Dahl.Nm
141c664bd46SJoel Dahlprogram should expect the string "ogin:".
142c664bd46SJoel DahlIf it fails to receive a login prompt within the time interval
1439b1aec48SLars Fredriksenallotted, it is to send a break sequence to the remote and then expect the
144c664bd46SJoel Dahlstring "ogin:".
145c664bd46SJoel DahlIf the first "ogin:" is received then the break sequence is
1469b1aec48SLars Fredriksennot generated.
147c664bd46SJoel Dahl.Pp
148c664bd46SJoel DahlOnce it received the login prompt the
149c664bd46SJoel Dahl.Nm
150c664bd46SJoel Dahlprogram will send the
151c664bd46SJoel Dahlstring ppp and then expect the prompt "ssword:".
152c664bd46SJoel DahlWhen it receives the
1539f65f104SPeter Wemmprompt for the password, it will send the password hello2u2.
154c664bd46SJoel Dahl.Pp
15587faa07bSSheldon HearnA carriage return is normally sent following the reply string.
15687faa07bSSheldon HearnIt is not
1579b1aec48SLars Fredriksenexpected in the "expect" string unless it is specifically requested by using
1589b1aec48SLars Fredriksenthe \\r character sequence.
159c664bd46SJoel Dahl.Pp
1609b1aec48SLars FredriksenThe expect sequence should contain only what is needed to identify the
16187faa07bSSheldon Hearnstring.
16287faa07bSSheldon HearnSince it is normally stored on a disk file, it should not contain
16387faa07bSSheldon Hearnvariable information.
16487faa07bSSheldon HearnIt is generally not acceptable to look for time
1659b1aec48SLars Fredriksenstrings, network identification strings, or other variable pieces of data as
1669b1aec48SLars Fredriksenan expect string.
167c664bd46SJoel Dahl.Pp
1689b1aec48SLars FredriksenTo help correct for characters which may be corrupted during the initial
169c664bd46SJoel Dahlsequence, look for the string "ogin:" rather than "login:".
170c664bd46SJoel DahlIt is possible
1719b1aec48SLars Fredriksenthat the leading "l" character may be received in error and you may never
17287faa07bSSheldon Hearnfind the string even though it was sent by the system.
17387faa07bSSheldon HearnFor this reason,
1749b1aec48SLars Fredriksenscripts look for "ogin:" rather than "login:" and "ssword:" rather than
1759b1aec48SLars Fredriksen"password:".
176c664bd46SJoel Dahl.Pp
1779b1aec48SLars FredriksenA very simple script might look like this:
178c664bd46SJoel Dahl.Pp
179c664bd46SJoel Dahl.D1 ogin: ppp ssword: hello2u2
180c664bd46SJoel Dahl.Pp
1819b1aec48SLars FredriksenIn other words, expect ....ogin:, send ppp, expect ...ssword:, send hello2u2.
182c664bd46SJoel Dahl.Pp
18387faa07bSSheldon HearnIn actual practice, simple scripts are rare.
18487faa07bSSheldon HearnAt the vary least, you
1859b1aec48SLars Fredriksenshould include sub-expect sequences should the original string not be
18687faa07bSSheldon Hearnreceived.
18787faa07bSSheldon HearnFor example, consider the following script:
188c664bd46SJoel Dahl.Pp
189c664bd46SJoel Dahl.D1 ogin:--ogin: ppp ssword: hello2u2
190c664bd46SJoel Dahl.Pp
19187faa07bSSheldon HearnThis would be a better script than the simple one used earlier.
19287faa07bSSheldon HearnThis would look
1939b1aec48SLars Fredriksenfor the same login: prompt, however, if one was not received, a single
19487faa07bSSheldon Hearnreturn sequence is sent and then it will look for login: again.
19587faa07bSSheldon HearnShould line
1969b1aec48SLars Fredriksennoise obscure the first login prompt then sending the empty line will
1979b1aec48SLars Fredriksenusually generate a login prompt again.
198c664bd46SJoel Dahl.Sh COMMENTS
19987faa07bSSheldon HearnComments can be embedded in the chat script.
20087faa07bSSheldon HearnA comment is a line which
201c664bd46SJoel Dahlstarts with the # (hash) character in column 1.
202c664bd46SJoel DahlSuch comment
20387faa07bSSheldon Hearnlines are just ignored by the chat program.
20487faa07bSSheldon HearnIf a '#' character is to
2053d793cf1SPeter Wemmbe expected as the first character of the expect sequence, you should
2063d793cf1SPeter Wemmquote the expect string.
2073d793cf1SPeter WemmIf you want to wait for a prompt that starts with a # (hash)
2083d793cf1SPeter Wemmcharacter, you would have to write something like this:
209c664bd46SJoel Dahl.Bd -literal -offset indent
2103d793cf1SPeter Wemm# Now wait for the prompt and send logout string
21131352a12STom Rhodes\&'# ' logout
212c664bd46SJoel Dahl.Ed
213c664bd46SJoel Dahl.Sh ABORT STRINGS
21487faa07bSSheldon HearnMany modems will report the status of the call as a string.
215c664bd46SJoel DahlThese strings may be
216c664bd46SJoel Dahl.Dv CONNECTED
217c664bd46SJoel Dahlor
218c664bd46SJoel Dahl.Dv NO CARRIER
219c664bd46SJoel Dahlor
220c664bd46SJoel Dahl.Dv BUSY .
221c664bd46SJoel DahlIt is often desirable to terminate the script should the modem fail to
22287faa07bSSheldon Hearnconnect to the remote.
22387faa07bSSheldon HearnThe difficulty is that a script would not know
22487faa07bSSheldon Hearnexactly which modem string it may receive.
225c664bd46SJoel DahlOn one attempt, it may receive
226c664bd46SJoel Dahl.Dv BUSY
227c664bd46SJoel Dahlwhile the next time it may receive
228c664bd46SJoel Dahl.Dv NO CARRIER .
229c664bd46SJoel Dahl.Pp
230c664bd46SJoel DahlThese "abort" strings may be specified in the script using the ABORT
23187faa07bSSheldon Hearnsequence.
23287faa07bSSheldon HearnIt is written in the script as in the following example:
233c664bd46SJoel Dahl.Pp
234c664bd46SJoel Dahl.D1 ABORT BUSY ABORT 'NO CARRIER' '' ATZ OK ATDT5551212 CONNECT
235c664bd46SJoel Dahl.Pp
23687faa07bSSheldon HearnThis sequence will expect nothing; and then send the string ATZ.
237c664bd46SJoel DahlThe expected response to this is the string
238c664bd46SJoel Dahl.Dv OK .
239c664bd46SJoel DahlWhen it receives
240c664bd46SJoel Dahl.Dv OK ,
24187faa07bSSheldon Hearnthe string ATDT5551212 to dial the telephone.
24287faa07bSSheldon HearnThe expected string is
243c664bd46SJoel Dahl.Dv CONNECT .
244c664bd46SJoel DahlIf the string
245c664bd46SJoel Dahl.Dv CONNECT
246c664bd46SJoel Dahlis received the remainder of the
24787faa07bSSheldon Hearnscript is executed.
24887faa07bSSheldon HearnHowever, should the modem find a busy telephone, it will
249c664bd46SJoel Dahlsend the string
250c664bd46SJoel Dahl.Dv BUSY .
25187faa07bSSheldon HearnThis will cause the string to match the abort
25287faa07bSSheldon Hearncharacter sequence.
25387faa07bSSheldon HearnThe script will then fail because it found a match to
25487faa07bSSheldon Hearnthe abort string.
255c664bd46SJoel DahlIf it received the string
256c664bd46SJoel Dahl.Dv NO CARRIER ,
257c664bd46SJoel Dahlit will abort
2584e86fcacSSheldon Hearnfor the same reason.
2594e86fcacSSheldon HearnEither string may be received.
26087faa07bSSheldon HearnEither string will
261c664bd46SJoel Dahlterminate the
262c664bd46SJoel Dahl.Nm
263c664bd46SJoel Dahlscript.
264c664bd46SJoel Dahl.Sh CLR_ABORT STRINGS
265c664bd46SJoel DahlThis sequence allows for clearing previously set
266c664bd46SJoel Dahl.Dv ABORT
267c664bd46SJoel Dahlstrings.
268c664bd46SJoel Dahl.Dv ABORT
269c664bd46SJoel Dahlstrings are kept in an array of a pre-determined size (at
270c664bd46SJoel Dahlcompilation time); CLR_ABORT will reclaim the space for cleared
2713d793cf1SPeter Wemmentries so that new strings can use that space.
272c664bd46SJoel Dahl.Sh SAY STRINGS
273c664bd46SJoel DahlThe
274c664bd46SJoel Dahl.Dv SAY
275c664bd46SJoel Dahldirective allows the script to send strings to the user
276c664bd46SJoel Dahlat the terminal via standard error.
277c664bd46SJoel DahlIf
278c664bd46SJoel Dahl.Nm
279c664bd46SJoel Dahlis being run by
2803d793cf1SPeter Wemmpppd, and pppd is running as a daemon (detached from its controlling
2813d793cf1SPeter Wemmterminal), standard error will normally be redirected to the file
282c664bd46SJoel Dahl.Pa /etc/ppp/connect-errors .
283c664bd46SJoel Dahl.Pp
284c664bd46SJoel Dahl.Dv SAY
285c664bd46SJoel Dahlstrings must be enclosed in single or double quotes.
286c664bd46SJoel DahlIf carriage return and line feed are needed in the string to be output,
2879595a75aSJoseph Koshyyou must explicitly add them to your string.
288c664bd46SJoel Dahl.Pp
289c664bd46SJoel DahlThe
290c664bd46SJoel Dahl.Dv SAY
291c664bd46SJoel Dahlstrings could be used to give progress messages in sections of
2923d793cf1SPeter Wemmthe script where you want to have 'ECHO OFF' but still let the user
293*6d6d6c36SGordon Berglingknow what is happening.
294*6d6d6c36SGordon BerglingAn example is:
295c664bd46SJoel Dahl.Bd -literal -offset indent
2963d793cf1SPeter WemmABORT BUSY
2973d793cf1SPeter WemmECHO OFF
2983d793cf1SPeter WemmSAY "Dialling your ISP...\\n"
29931352a12STom Rhodes\&'' ATDT5551212
3003d793cf1SPeter WemmTIMEOUT 120
3013d793cf1SPeter WemmSAY "Waiting up to 2 minutes for connection ... "
3023d793cf1SPeter WemmCONNECT ''
30331352a12STom RhodesSAY "Connected, now logging in ...\\n"
3043d793cf1SPeter Wemmogin: account
3053d793cf1SPeter Wemmssword: pass
306c664bd46SJoel Dahl$ SAY "Logged in OK ...\\n" \fIetc ...\fR
307c664bd46SJoel Dahl.Ed
308c664bd46SJoel Dahl.Pp
309c664bd46SJoel DahlThis sequence will only present the
310c664bd46SJoel Dahl.Dv SAY
311c664bd46SJoel Dahlstrings to the user and all
31287faa07bSSheldon Hearnthe details of the script will remain hidden.
31387faa07bSSheldon HearnFor example, if the
3143d793cf1SPeter Wemmabove script works, the user will see:
315c664bd46SJoel Dahl.Bd -literal -offset indent
3163d793cf1SPeter WemmDialling your ISP...
3173d793cf1SPeter WemmWaiting up to 2 minutes for connection ... Connected, now logging in ...
3183d793cf1SPeter WemmLogged in OK ...
319c664bd46SJoel Dahl.Ed
320c664bd46SJoel Dahl.Sh REPORT STRINGS
321c664bd46SJoel DahlA report string is similar to the
322c664bd46SJoel Dahl.Dv ABORT
323c664bd46SJoel Dahlstring.
32487faa07bSSheldon HearnThe difference
3259f65f104SPeter Wemmis that the strings, and all characters to the next control character
3269f65f104SPeter Wemmsuch as a carriage return, are written to the report file.
327c664bd46SJoel Dahl.Pp
3289f65f104SPeter WemmThe report strings may be used to isolate the transmission rate of the
32987faa07bSSheldon Hearnmodem's connect string and return the value to the chat user.
33087faa07bSSheldon HearnThe
3319f65f104SPeter Wemmanalysis of the report string logic occurs in conjunction with the
33287faa07bSSheldon Hearnother string processing such as looking for the expect string.
33387faa07bSSheldon HearnThe use
3349f65f104SPeter Wemmof the same string for a report and abort sequence is probably not
3359f65f104SPeter Wemmvery useful, however, it is possible.
336c664bd46SJoel Dahl.Pp
3379f65f104SPeter WemmThe report strings to no change the completion code of the program.
338c664bd46SJoel Dahl.Pp
339c664bd46SJoel DahlThese "report" strings may be specified in the script using the
340c664bd46SJoel Dahl.Dv REPORT
34187faa07bSSheldon Hearnsequence.
34287faa07bSSheldon HearnIt is written in the script as in the following example:
343c664bd46SJoel Dahl.Pp
344c664bd46SJoel Dahl.D1 REPORT CONNECT ABORT BUSY '' ATDT5551212 CONNECT '' ogin: account
345c664bd46SJoel Dahl.Pp
3469f65f104SPeter WemmThis sequence will expect nothing; and then send the string
34787faa07bSSheldon HearnATDT5551212 to dial the telephone.
34887faa07bSSheldon HearnThe expected string is
349c664bd46SJoel Dahl.Dv CONNECT .
350c664bd46SJoel DahlIf the string
351c664bd46SJoel Dahl.Dv CONNECT
352c664bd46SJoel Dahlis received the remainder
35387faa07bSSheldon Hearnof the script is executed.
35487faa07bSSheldon HearnIn addition the program will write to the
3559f65f104SPeter Wemmexpect-file the string "CONNECT" plus any characters which follow it
3569f65f104SPeter Wemmsuch as the connection rate.
357c664bd46SJoel Dahl.Sh CLR_REPORT STRINGS
358c664bd46SJoel DahlThis sequence allows for clearing previously set
359c664bd46SJoel Dahl.Dv REPORT
360c664bd46SJoel Dahlstrings.
361c664bd46SJoel Dahl.Dv REPORT
362c664bd46SJoel Dahlstrings are kept in an array of a pre-determined size (at
363c664bd46SJoel Dahlcompilation time); CLR_REPORT will reclaim the space for cleared
3643d793cf1SPeter Wemmentries so that new strings can use that space.
365c664bd46SJoel Dahl.Sh ECHO
3663d793cf1SPeter WemmThe echo options controls whether the output from the modem is echoed
367c664bd46SJoel Dahlto
368c664bd46SJoel Dahl.Em stderr .
369c664bd46SJoel DahlThis option may be set with the
370c664bd46SJoel Dahl.Fl e
371c664bd46SJoel Dahloption, but
372c664bd46SJoel Dahlit can also be controlled by the
373c664bd46SJoel Dahl.Dv ECHO
374c664bd46SJoel Dahlkeyword.
37587faa07bSSheldon HearnThe "expect-send"
376c664bd46SJoel Dahlpair
377c664bd46SJoel Dahl.Dv ECHO ON
378c664bd46SJoel Dahlenables echoing, and
379c664bd46SJoel Dahl.Dv ECHO OFF
38087faa07bSSheldon Hearndisables it.
38187faa07bSSheldon HearnWith this keyword you can select which parts of the
38287faa07bSSheldon Hearnconversation should be visible.
38387faa07bSSheldon HearnFor instance, with the following
3843d793cf1SPeter Wemmscript:
385c664bd46SJoel Dahl.Bd -literal -offset indent
3863d793cf1SPeter WemmABORT   'BUSY'
3873d793cf1SPeter WemmABORT   'NO CARRIER'
38831352a12STom Rhodes\&''      ATZ
3893d793cf1SPeter WemmOK\\r\\n  ATD1234567
3903d793cf1SPeter Wemm\\r\\n    \\c
3913d793cf1SPeter WemmECHO    ON
3923d793cf1SPeter WemmCONNECT \\c
3933d793cf1SPeter Wemmogin:   account
394c664bd46SJoel Dahl.Ed
395c664bd46SJoel Dahl.Pp
3963d793cf1SPeter Wemmall output resulting from modem configuration and dialing is not visible,
397c664bd46SJoel Dahlbut starting with the
398c664bd46SJoel Dahl.Dv CONNECT
399c664bd46SJoel Dahlor
400c664bd46SJoel Dahl.Dv BUSY
401c664bd46SJoel Dahlmessage, everything
4023d793cf1SPeter Wemmwill be echoed.
403c664bd46SJoel Dahl.Sh HANGUP
404c664bd46SJoel DahlThe
405c664bd46SJoel Dahl.Dv HANGUP
406c664bd46SJoel Dahloptions control whether a modem hangup should be considered
407c664bd46SJoel Dahlas an error or not.
408c664bd46SJoel DahlThis option is useful in scripts for dialling
409c664bd46SJoel Dahlsystems which will hang up and call your system back.
410c664bd46SJoel DahlThe
411c664bd46SJoel Dahl.Dv HANGUP
412c664bd46SJoel Dahloptions can be
413c664bd46SJoel Dahl.Dv ON
414c664bd46SJoel Dahlor
415c664bd46SJoel Dahl.Dv OFF .
416c664bd46SJoel Dahl.Pp
417c664bd46SJoel DahlWhen
418c664bd46SJoel Dahl.Dv HANGUP
419c664bd46SJoel Dahlis set
420c664bd46SJoel Dahl.Dv OFF
421c664bd46SJoel Dahland the modem hangs up (e.g., after the first
422c664bd46SJoel Dahlstage of logging in to a callback system),
423c664bd46SJoel Dahl.Nm
424c664bd46SJoel Dahlwill continue
4253d793cf1SPeter Wemmrunning the script (e.g., waiting for the incoming call and second
426c664bd46SJoel Dahlstage login prompt).
427c664bd46SJoel DahlAs soon as the incoming call is connected, you
428c664bd46SJoel Dahlshould use the
429c664bd46SJoel Dahl.Dv HANGUP ON
430c664bd46SJoel Dahldirective to reinstall normal hang up
431c664bd46SJoel Dahlsignal behavior.
432c664bd46SJoel DahlHere is a (simple) example script:
433c664bd46SJoel Dahl.Bd -literal -offset indent
4343d793cf1SPeter WemmABORT   'BUSY'
43531352a12STom Rhodes\&''      ATZ
4363d793cf1SPeter WemmOK\\r\\n  ATD1234567
4373d793cf1SPeter Wemm\\r\\n    \\c
4383d793cf1SPeter WemmCONNECT \\c
43931352a12STom Rhodes\&'Callback login:' call_back_ID
4403d793cf1SPeter WemmHANGUP OFF
4413d793cf1SPeter WemmABORT "Bad Login"
44231352a12STom Rhodes\&'Callback Password:' Call_back_password
4433d793cf1SPeter WemmTIMEOUT 120
4443d793cf1SPeter WemmCONNECT \\c
4453d793cf1SPeter WemmHANGUP ON
4463d793cf1SPeter WemmABORT "NO CARRIER"
4473d793cf1SPeter Wemmogin:--BREAK--ogin: real_account
4483d793cf1SPeter Wemm\fIetc ...\fR
449c664bd46SJoel Dahl.Ed
450c664bd46SJoel Dahl.Sh TIMEOUT
45187faa07bSSheldon HearnThe initial timeout value is 45 seconds.
452c664bd46SJoel DahlThis may be changed using the
453c664bd46SJoel Dahl.Fl t
4549b1aec48SLars Fredriksenparameter.
455c664bd46SJoel Dahl.Pp
4569b1aec48SLars FredriksenTo change the timeout value for the next expect string, the following
4579b1aec48SLars Fredriksenexample may be used:
458c664bd46SJoel Dahl.Bd -literal -offset indent
4596abc8fd6SMike PritchardATZ OK ATDT5551212 CONNECT TIMEOUT 10 ogin:--ogin: TIMEOUT 5 assword: hello2u2
460c664bd46SJoel Dahl.Ed
461c664bd46SJoel Dahl.Pp
4629b1aec48SLars FredriksenThis will change the timeout to 10 seconds when it expects the login:
46387faa07bSSheldon Hearnprompt.
46487faa07bSSheldon HearnThe timeout is then changed to 5 seconds when it looks for the
4659b1aec48SLars Fredriksenpassword prompt.
466c664bd46SJoel Dahl.Pp
4679b1aec48SLars FredriksenThe timeout, once changed, remains in effect until it is changed again.
468c664bd46SJoel Dahl.Sh SENDING EOT
469c664bd46SJoel DahlThe special reply string of
470c664bd46SJoel Dahl.Dv EOT
471c664bd46SJoel Dahlindicates that the chat program
472c664bd46SJoel Dahlshould send an
473c664bd46SJoel Dahl.Dv EOT
474c664bd46SJoel Dahlcharacter to the remote.
47587faa07bSSheldon HearnThis is normally the
47687faa07bSSheldon HearnEnd-of-file character sequence.
47787faa07bSSheldon HearnA return character is not sent
478c664bd46SJoel Dahlfollowing the
479c664bd46SJoel Dahl.Dv EOT .
480c664bd46SJoel Dahl.Pp
481c664bd46SJoel DahlThe
482c664bd46SJoel Dahl.Dv EOT
483c664bd46SJoel Dahlsequence may be embedded into the send string using the
484c664bd46SJoel Dahlsequence ^D.
485c664bd46SJoel Dahl.Sh GENERATING BREAK
486c664bd46SJoel DahlThe special reply string of
487c664bd46SJoel Dahl.Dv BREAK
488c664bd46SJoel Dahlwill cause a break condition
4894e86fcacSSheldon Hearnto be sent.
4904e86fcacSSheldon HearnThe break is a special signal on the transmitter.
49187faa07bSSheldon HearnThe
4929b1aec48SLars Fredriksennormal processing on the receiver is to change the transmission rate.
4939b1aec48SLars FredriksenIt may be used to cycle through the available transmission rates on
4949b1aec48SLars Fredriksenthe remote until you are able to receive a valid login prompt.
495c664bd46SJoel Dahl.Pp
4969b1aec48SLars FredriksenThe break sequence may be embedded into the send string using the
4979b1aec48SLars Fredriksen\fI\\K\fR sequence.
498c664bd46SJoel Dahl.Sh ESCAPE SEQUENCES
49987faa07bSSheldon HearnThe expect and reply strings may contain escape sequences.
50087faa07bSSheldon HearnAll of the
50187faa07bSSheldon Hearnsequences are legal in the reply string.
50287faa07bSSheldon HearnMany are legal in the expect.
5039b1aec48SLars FredriksenThose which are not valid in the expect sequence are so indicated.
504c664bd46SJoel Dahl.Bl -tag -width indent
505c664bd46SJoel Dahl.It ''
50687faa07bSSheldon HearnExpects or sends a null string.
50787faa07bSSheldon HearnIf you send a null string then it will still
50887faa07bSSheldon Hearnsend the return character.
50987faa07bSSheldon HearnThis sequence may either be a pair of apostrophe
5109b1aec48SLars Fredriksenor quote characters.
511441dec84SJoel Dahl.It \eb
5129b1aec48SLars Fredriksenrepresents a backspace character.
513441dec84SJoel Dahl.It \ec
51487faa07bSSheldon HearnSuppresses the newline at the end of the reply string.
51587faa07bSSheldon HearnThis is the only
51687faa07bSSheldon Hearnmethod to send a string without a trailing return character.
51787faa07bSSheldon HearnIt must
51887faa07bSSheldon Hearnbe at the end of the send string.
51987faa07bSSheldon HearnFor example,
520c664bd46SJoel Dahlthe sequence hello\\c will simply send the characters h, e, l, l, o
521c664bd46SJoel Dahl.Pq Em not valid in expect .
522441dec84SJoel Dahl.It \ed
52387faa07bSSheldon HearnDelay for one second.
52487faa07bSSheldon HearnThe program uses sleep(1) which will delay to a
525c664bd46SJoel Dahlmaximum of one second
526c664bd46SJoel Dahl.Pq Em not valid in expect .
527441dec84SJoel Dahl.It \eK
528c664bd46SJoel DahlInsert a
529c664bd46SJoel Dahl.Dv BREAK
530c664bd46SJoel Dahl.Pq Em not valid in expect .
531441dec84SJoel Dahl.It \en
5329b1aec48SLars FredriksenSend a newline or linefeed character.
533441dec84SJoel Dahl.It \eN
53487faa07bSSheldon HearnSend a null character.
535c664bd46SJoel DahlThe same sequence may be represented by \\0
536c664bd46SJoel Dahl.Pq Em not valid in expect .
537441dec84SJoel Dahl.It \ep
53887faa07bSSheldon HearnPause for a fraction of a second.
539c664bd46SJoel DahlThe delay is 1/10th of a second
540c664bd46SJoel Dahl.Pq Em not valid in expect .
541441dec84SJoel Dahl.It \eq
5429ef62d7cSMike PritchardSuppress writing the string to
543c664bd46SJoel Dahl.Xr syslogd 8 .
5449ef62d7cSMike PritchardThe string ?????? is
545c664bd46SJoel Dahlwritten to the log in its place
546c664bd46SJoel Dahl.Pq Em not valid in expect .
547441dec84SJoel Dahl.It \er
5489b1aec48SLars FredriksenSend or expect a carriage return.
549441dec84SJoel Dahl.It \es
55087faa07bSSheldon HearnRepresents a space character in the string.
55187faa07bSSheldon HearnThis may be used when it
55287faa07bSSheldon Hearnis not desirable to quote the strings which contains spaces.
55387faa07bSSheldon HearnThe
5549b1aec48SLars Fredriksensequence 'HI TIM' and HI\\sTIM are the same.
555441dec84SJoel Dahl.It \et
5569b1aec48SLars FredriksenSend or expect a tab character.
557441dec84SJoel Dahl.It \e
5589b1aec48SLars FredriksenSend or expect a backslash character.
559441dec84SJoel Dahl.It \eddd
5609b1aec48SLars FredriksenCollapse the octal digits (ddd) into a single ASCII character and send that
561c664bd46SJoel Dahlcharacter
562c664bd46SJoel Dahl.Pq Em some characters are not valid in expect .
563c664bd46SJoel Dahl.It \^^C
5649b1aec48SLars FredriksenSubstitute the sequence with the control character represented by C.
565c664bd46SJoel DahlFor example, the character DC1 (17) is shown as \^^Q
566c664bd46SJoel Dahl.Pq Em some characters are not valid in expect .
567c664bd46SJoel Dahl.El
568c664bd46SJoel Dahl.Sh TERMINATION CODES
569c664bd46SJoel DahlThe
570c664bd46SJoel Dahl.Nm
571c664bd46SJoel Dahlprogram will terminate with the following completion
5729f65f104SPeter Wemmcodes.
573c664bd46SJoel Dahl.Bl -tag -width indent
574c664bd46SJoel Dahl.It 0
57587faa07bSSheldon HearnThe normal termination of the program.
57687faa07bSSheldon HearnThis indicates that the script
5779f65f104SPeter Wemmwas executed without error to the normal conclusion.
578c664bd46SJoel Dahl.It 1
5799f65f104SPeter WemmOne or more of the parameters are invalid or an expect string was too
58087faa07bSSheldon Hearnlarge for the internal buffers.
58187faa07bSSheldon HearnThis indicates that the program as not
5829f65f104SPeter Wemmproperly executed.
583c664bd46SJoel Dahl.It 2
58487faa07bSSheldon HearnAn error occurred during the execution of the program.
58587faa07bSSheldon HearnThis may be due
5869f65f104SPeter Wemmto a read or write operation failing for some reason or chat receiving
587c664bd46SJoel Dahla signal such as
588c664bd46SJoel Dahl.Dv SIGINT .
589c664bd46SJoel Dahl.It 3
590c664bd46SJoel DahlA timeout event occurred when there was an
591c664bd46SJoel Dahl.Em expect
592c664bd46SJoel Dahlstring without
59387faa07bSSheldon Hearnhaving a "-subsend" string.
59487faa07bSSheldon HearnThis may mean that you did not program the
5959f65f104SPeter Wemmscript correctly for the condition or that some unexpected event has
5969f65f104SPeter Wemmoccurred and the expected string could not be found.
597c664bd46SJoel Dahl.It 4
598c664bd46SJoel DahlThe first string marked as an
599c664bd46SJoel Dahl.Dv ABORT
600c664bd46SJoel Dahlcondition occurred.
601c664bd46SJoel Dahl.It 5
602c664bd46SJoel DahlThe second string marked as an
603c664bd46SJoel Dahl.Dv ABORT
604c664bd46SJoel Dahlcondition occurred.
605c664bd46SJoel Dahl.It 6
606c664bd46SJoel DahlThe third string marked as an
607c664bd46SJoel Dahl.Dv ABORT
608c664bd46SJoel Dahlcondition occurred.
609c664bd46SJoel Dahl.It 7
610c664bd46SJoel DahlThe fourth string marked as an
611c664bd46SJoel Dahl.Dv ABORT
612c664bd46SJoel Dahlcondition occurred.
613c664bd46SJoel Dahl.It ...
614c664bd46SJoel DahlThe other termination codes are also strings marked as an
615c664bd46SJoel Dahl.Dv ABORT
6169f65f104SPeter Wemmcondition.
617c664bd46SJoel Dahl.El
618c664bd46SJoel Dahl.Pp
6199f65f104SPeter WemmUsing the termination code, it is possible to determine which event
62087faa07bSSheldon Hearnterminated the script.
62187faa07bSSheldon HearnIt is possible to decide if the string "BUSY"
622c664bd46SJoel Dahlwas received from the modem as opposed to "NO DIAL TONE".
623c664bd46SJoel DahlWhile the
6249f65f104SPeter Wemmfirst event may be retried, the second will probably have little
6259f65f104SPeter Wemmchance of succeeding during a retry.
626c664bd46SJoel Dahl.Sh SEE ALSO
627c664bd46SJoel DahlAdditional information about
628c664bd46SJoel Dahl.Nm
629c664bd46SJoel Dahlscripts may be found with UUCP
63087faa07bSSheldon Hearndocumentation.
631c664bd46SJoel DahlThe
632c664bd46SJoel Dahl.Nm
633c664bd46SJoel Dahlscript was taken from the ideas proposed
634c664bd46SJoel Dahlby the scripts used by the uucico program.
635c664bd46SJoel Dahl.Pp
636c664bd46SJoel Dahl.Xr syslog 3 ,
637c664bd46SJoel Dahl.Xr syslogd 8
638c664bd46SJoel Dahl.Sh COPYRIGHT
639c664bd46SJoel DahlThe
640c664bd46SJoel Dahl.Nm
641c664bd46SJoel Dahlprogram is in public domain.
64287faa07bSSheldon HearnThis is not the GNU public
64387faa07bSSheldon Hearnlicense.
64487faa07bSSheldon HearnIf it breaks then you get to keep both pieces.
645