Manpages

NAME

chat - 与 数 据 机 自 动 沟 通 的 指 令 稿

总 览 SYNOPSIS

chat [ options ] script

描 述 DESCRIPTION

chat 程 式 在 电 脑 与 数 据 机 之 间 定 义 沟 通 交 换 事 宜 。 它 最 主 要 的 目 的 是 用 来 在 点 对 点 协 定 的 隐 形 程 式 (pppd) 以 及 远 端 的 pppd 程 序 之 间 建 立 连 线 。

选 项 OPTIONS

-f <chat file> 从 chat 档 案 读 取 chat 指 令 稿 。 这 个 选 项 的 使 用 与 chat 的 令 稿 参 数 互 斥 (mutually exclusive)。 使 用 者 必 须 具 有 存 取 该 档 案 的 读 取 权 。 在 档 案 中 允 许 多 线 (multiple lines)设 定 。 应 该 要 以 空 白 或 是 横 向 定 位 (horizontal tab)字 元 来 分 隔 字 串 。
-t
<timeout> 对 于 所 要 接 收 的 期 待 字 串 (expected string)设 定 逾 时 限 制 。 如 果 在 该 时 间 限 制 内 没 有 接 收 到 该 字 串 的 话 那 么 就 不 送 出 回 复 字 串 (reply string)。 可 以 送 出 一 个 变 通 (alternate)的 回 复 或 者 如 果 没 有 变 通 的 回 复 字 串 则 该 指 令 稿 将 会 失 败 。 一 个 失 败 的 指 令 稿 将 会 使 得 chat 程 式 以 一 个 非 零 的 错 误 码 结 束 。
-r
<report file>

Set the file for output of the report strings. If you use the keyword REPORT, the resulting strings are written to this file. If this option is not used and you still use REPORT keywords, the stderr file is used for the report strings.

-e

Start with the echo option turned on. Echoing may also be turned on or off at specific points in the chat script by using the ECHO keyword. When echoing is enabled, all output from the modem is echoed to stderr.

-E

Enables environment variable substituion within chat scripts using the standard $xxx syntax.

-v

要 求 chat 指 令 稿 以 冗 长 (verbose)模 式 执 行 。 这 个 chat 程 式 接 下 来 会 将 所 有 从 数 据 机 接 收 的 文 字 以 及 输 出 的 字 串 记 录 到 SYSLOG 去 。 The default is to log through the SYSLOG; the logging method may be altered with the -S and -s flags.
-V

Request that the chat script be executed in a stderr verbose mode. The chat program will then log all text received from the modem and the output strings sent to the modem to the stderr device. This device is usually the local console at the station running the chat or pppd program.

-s

Use stderr. All log messages from ’-v’ and all error messages will be sent to stderr.

-S

Do not use the SYSLOG. By default, error messages are sent to the SYSLOG. The use of -S will prevent both log messages from ’-v’ and error messages from being sent to the SYSLOG.

-T <phone number>

Pass in an arbitary string, usually a phone number, that will be substituted for the \T substitution metacharacter in a send string.

-U <phone number 2>

Pass in a second string, usually a phone number, that will be substituted for the \U substitution metacharacter in a send string. This is useful when dialing an ISDN terminal adapter that requires two numbers.

script

script 如 果 指 令 稿 没 有 以 -f 选 项 指 定 在 档 案 里 那 么 该 指 令 稿 会 如 同 参 数 般 被 包 含 在 chat 程 式 里 。

CHAT 脚 本 SCRIPT

chat 脚 本 定 义 通 讯 过 程 一 个 指 令 稿 里 包 含 一 个 或 多 个 〞 期 待 对 方 送 出 (expect-send)〞 的 配 对 字 串 (pairs of string), 以 空 白 隔 开 , 还 有 一 个 选 择 性 的 〞 期 待 对 方 送 出 之 候 补 (subexpect-subsend)〞 配 对 字 串 , 以 短 线 (dash)隔 开 。 像 下 面 这 个 例 子 :

ogin:-BREAK-ogin: ppp ssword: hello2u2 这 一 行 指 示 chat 程 式 应 该 期 待 "ogin:" 这 个 字 串 。 如 果 在 所 分 配 的 时 间 区 间 内 接 收 签 入 提 示 失 败 的 话 , 那 它 就 送 出 一 个 中 断 程 序 (break sequence)给 远 端 然 后 期 待 "ogin:" 这 个 字 串 。 如 果 第 一 个 "ogin:" 被 接 收 到 那 么 中 断 程 序 就 不 会 产 生 。 一 旦 它 接 收 到 该 签 入 提 示 则 chat 程 式 将 会 送 出 ppp 这 个 字 串 然 后 期 待 "ssword:" 这 个 提 示 。 当 它 接 收 到 密 码 提 示 以 后 , 它 将 会 送 出 密 码 hello2u2 。 一 般 在 回 复 字 串 后 面 会 跟 著 送 出 一 个 机 架 返 回 (carriage return)。 在 〞 期字 元 程 序 (character sequence)指 定 为 必 须 否 则 不 会 期 待 待 〞 字 串 里 除 非 以 它 的 出 现 。 期 待 程 序 (expect sequence)应 该 只 包 含 辨 认 字 串 所 需 要 的 资 料 。 因 为 它 一 般 是 储 放 在 磁 碟 档 案 里 , 它 不 应 该 包 含 变 动 的 资 讯 。 通 常 以 期 待 字 串 来 寻 找 时 间 字 串 (time strings), 网 路 辨 识 字 串 (network iden- tification strings), 或 是 其 它 变 动 的 资 料 是 不 被 接 受 的 。 为 求 协 助 修 正 在 初 始 化 程 序 中 (initial sequence) 可 能 会 传 送 错 误 的 字 元 , 所 以 寻 找 "ogin:" 这 个 字 串 而 不 是 "login:" 。 开 头 的 "l" 字 元 可 能 接 收 错 误 而 你 永 远 找 不 到 该 字 串 , 即 使 它 已 经 被 系 统 送 出 。 因 此 缘 故 , 指 令 稿 寻 找 "ogin:" 而 不 是 "login:" 以 及 "ssword" 而 不 是 "password:" 。 一 个 非 常 简 单 的 指 令 稿 看 起 来 可 能 像 这 样 :

ogin: ppp ssword: hello2u2 换 句 话 说 , 期 待 ...ogin:, 送 出 ppp, 期 待 ...ssword:, 再 送 出 hello2u2 。 在 实 际 使 用 上 , 简 单 的 指 令 稿 是 罕 见 的 。 最 少 最 少 , 原 先 的 字 串 没 有 被 接 收 时 你 应 该 要 把 候 补 期 待 (sub-sequences)包 括 进 来 。 例 如 , 考 虑 下 面 这 个 例 子 :

ogin:--ogin: ppp ssword: hello2u2 这 会 是 一 个 比 前 面 所 用 的 简 单 指 令 稿 更 好 的 指 令 稿 。 这 个 会 寻 找 相 同 同 的 login: 提 示 , 然 而 , 如 果 没 有 接 收 到 的 话 , 会 送 出 一 个 单 独 的 返 回 程 序 (return sequence)并 且 它 会 接 著 再 次 寻 找 login: 。 要 是 杂 杂 讯 掩 盖 掉 第 一 个 login 提 示 那 么 接 著 送 出 空 线 路 (empty line)经 常 将 会 再 次 产 生 签 入 提 示 。

COMMENTS

Comments can be embedded in the chat script. A comment is a line which starts with the # (hash) character in column 1. Such comment lines are just ignored by the chat program. If a ’#’ character is to be expected as the first character of the expect sequence, you should quote the expect string. If you want to wait for a prompt that starts with a # (hash) character, you would have to write something like this:

# Now wait for the prompt and send logout string
´# ’ logout

SENDING DATA FROM A FILE

If the string to send starts with an at sign (@), the rest of the string is taken to be the name of a file to read to get the string to send. 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 provides a way for chat to communicate with another program, for example, a program to prompt the user and receive a password typed in.

放 弃 字 符 串 ABORT STRINGS

许 多 数 据 机 会 以 字 串 来 回 报 呼 叫 的 状 况 。 这 些 字 串 可 能 是 CONNECTED 或 是 NO CARRIER 或 是 BUSY 。 通 常 要 是 数 据 机 连 线 到 远 端 失 败 的 话 应 该 会 希 望 结 束 指 令 稿 。 困 难 是 指 令 稿 不 会 确 实 地 知 道 它 可 能 接 收 到 哪 个 数 据 机 字 串 。 在 某 次 尝 试 时 , 他 可 能 接 收 到 BUSY 然 而 下 次 它 可 能 接 收 到 NO CARRIER 。 这 些 〞 失 败 〞 字 串 可 以 用 ABORT 程 序 指 定 到 指 令 稿 中 。 像 是 下 面 这 个 例 子 般 地 写 到 指 令 稿 里 :

ABORT BUSY ABORT ’NO CARRIER’ ’’ ATZ OK ATDT5551212 CONNECT 这 个 程 序 将 不 会 期 待 什 么 ; 而 且 接 著 送 出 ATZ 这 个 字 串 。 对 此 期 待 的 回 应 是 OK 这 个 字 串 。 当 它 接 收 到 OK 时 , 字 串 ADTD5551212 就 进 行 拨 号 。 期 待 字 串 是 CONNECT 。 如 果 字 串 CONNECT 被 接 收 到 那 么 就 会 执 行 指 令 稿 其 余 的 部 份 。 然 而 , 要 是 数 据 机 发 现 电 话 忙 线 , 他 将 会 送 出 BUSY 这 个 字 串 。 这 会 使 得 该 字 串 符 合 失 败 字 元 程 序 (abort char- acter)。 这 个 指 令 稿 将 会 因 为 它 发 现 一 个 失 败 字 串 (abort string)而 失 败 (fail)。 如 果 他 接 收 到 的 是 NO CARRIER 字 串 , 它 也 会 因 为 同 样 的 原 因 而 失 败 。 不 是 可 以 接 收 到 字 串 就 是 字 串 将 终 结 chat 指 令 稿 。

CLR_ABORT STRINGS

This sequence allows for clearing previously set ABORT strings. ABORT strings are kept in an array of a pre-determined size (at compilation time); CLR_ABORT will reclaim the space for cleared entries so that new strings can use that space.

SAY STRINGS

The SAY directive allows the script to send strings to the user at the terminal via standard error. If chat is being run by pppd, and pppd is running as a daemon (detached from its controlling terminal), standard error will normally be redirected to the file /etc/ppp/connect-errors.

SAY strings must be enclosed in single or double quotes. If carriage return and line feed are needed in the string to be output, you must explicitely add them to your string.

The SAY strings could be used to give progress messages in sections of the script where you want to have ’ECHO OFF’ but still let the user know what is happening. An example is:

ABORT BUSY
ECHO OFF
SAY "Dialling your ISP...\n"
´’ ATDT5551212
TIMEOUT 120
SAY "Waiting up to 2 minutes for connection ... "
CONNECT ’’
SAY "Connected, now logging in ...0
ogin: account
ssword: pass
$ SAY "Logged in OK ...0 etc ...

This sequence will only present the SAY strings to the user and all the details of the script will remain hidden. For example, if the above script works, the user will see:

Dialling your ISP...
Waiting up to 2 minutes for connection ... Connected, now logging in ...
Logged in OK ...

REPORT STRINGS

A report string is similar to the ABORT string. The difference is that the strings, and all characters to the next control character such as a carriage return, are written to the report file.

The report strings may be used to isolate the transmission rate of the modem’s connect string and return the value to the chat user. The analysis of the report string logic occurs in conjunction with the other string processing such as looking for the expect string. The use of the same string for a report and abort sequence is probably not very useful, however, it is possible.

The report strings to no change the completion code of the program.

These "report" strings may be specified in the script using the REPORT sequence. It is written in the script as in the following example:

REPORT CONNECT ABORT BUSY ’’ ATDT5551212 CONNECT ’’ ogin: account

This sequence will expect nothing; and then send the string ATDT5551212 to dial the telephone. The expected string is CONNECT. If the string CONNECT is received the remainder of the script is executed. In addition the program will write to the expect-file the string "CONNECT" plus any characters which follow it such as the connection rate.

CLR_REPORT STRINGS

This sequence allows for clearing previously set REPORT strings. REPORT strings are kept in an array of a pre-determined size (at compilation time); CLR_REPORT will reclaim the space for cleared entries so that new strings can use that space.

ECHO

The echo options controls whether the output from the modem is echoed to stderr. This option may be set with the -e option, but it can also be controlled by the ECHO keyword. The "expect-send" pair ECHO ON enables echoing, and ECHO OFF disables it. With this keyword you can select which parts of the conversation should be visible. For instance, with the following script:

ABORT ’BUSY’
ABORT ’NO CARRIER’
’’
ATZ
OK\r\n ATD1234567
\r\n \c
ECHO ON
CONNECT \c
ogin: account

all output resulting from modem configuration and dialing is not visible, but starting with the CONNECT (or BUSY) message, everything will be echoed.

HANGUP

The HANGUP options control whether a modem hangup should be considered as an error or not. This option is useful in scripts for dialling systems which will hang up and call your system back. The HANGUP options can be ON or OFF.
When HANGUP is set OFF and the modem hangs up (e.g., after the first stage of logging in to a callback system), chat will continue running the script (e.g., waiting for the incoming call and second stage login prompt). As soon as the incoming call is connected, you should use the HANGUP ON directive to reinstall normal hang up signal behavior. Here is an (simple) example script:

ABORT ’BUSY’
´´ ATZ
OK\r\n ATD1234567
\r\n \c
CONNECT \c
´Callback login:’ call_back_ID
HANGUP OFF
ABORT "Bad Login"
´Callback Password:’ Call_back_password
TIMEOUT 120
CONNECT \c
HANGUP ON
ABORT "NO CARRIER"
ogin:--BREAK--ogin: real_account
etc ...

超 时 TIMEOUT

初 始 的 逾 时 值 是 45 秒 。 这 可 以 用 -t 参 数 来 加 以 改 变 。 要 对 下 一 个 期 待 字 串 改 变 逾 时 值 的 话 , 可 以 使 用 下 面 这 个 例 子 :

ATZ OK ATDT5551212 CONNECT TIMEOUT 10 ogin:--ogin: TIMEOUT 5 assword: hello2u2 这 将 会 在 期 待 "login:" 提 示 的 时 候 把 逾 时 限 制 改 成 10 秒 。 逾 时 限 制 接 著 在 它 寻 找 密 码 提 示 时 被 改 成 5 秒 。 逾 时 限 制 一 旦 改 变 就 会 持 续 作 用 直 到 它 再 度 被 改 变 。

SENDING 发 送 EOT

EOT 这 个 特 别 的 回 复 字 串 指 示 chat 程 式 应 该 送 出 一 个 EOT 字 元 到 远 端 去 。 这 是 一 般 的 档 案 结 束 (End-of-file)字 元 程 序 。 在 EOT 后 面 并 不 会 跟 著 送 出 一 个 返 回 字 元 (return)。 这 个 EOT 程 序 可 以 用 ^D 序 列 嵌 入 到 送 出 的 字 串 里 。

产 生 中 断 GENERATING BREAK

BREAK 这 个 特 别 的 回 复 字 串 将 会 使 得 一 个 中 断 情 况 被 送 出 。 这 个 中 断 是 传 送 端 的 一 个 特 殊 。 接 收 端 一 般 对 此 的 处 理 是 改 变 传 输 率 。 它 可 以 用 来 循 环 测 试 远 端 可 能 的 传 输 率 直 到 你 能 够 接 到 有 效 的 签 入 提 示 。 这 个 中 断 程 序 可 以 用 \K 序 列 嵌 入 到 送 出 的 字 串 里 。

转 义 序 列 ESCAPE SEQUENCES

期 待 以 及 回 复 字 串 可 以 包 含 转 义 序 列 。 所 有 这 种 程 序 在 回 复 字 串 中 都 是 合 法 的 。 有 许 多 在 期 待 字 串 中 是 合 法 的 。 那 些 在 期 待 程 序 中 无 效 的 会 被 指 出 。

’’ 期 待 或 送 出 一 个 空 字 串

(null string) 。 如 果 你 送 出 一 个 空 字 串 那 么 它

还 会 送 出 一 个 返 回 字 元 。 这 个 程 序 可 以 是 一 对 省 略 符 号 (apostrophe)或 者 也 可 以 是 引 用 字 元 。

\b 代 表 一 个 退 位

(backspace)字 元 。

\c 抑 制 在 回 复 字

串 结 尾 的 新 列 (newline)字 元 。 这 是 送 出 没 有 返 回 字 元 尾 随 的 字 串 的 唯 一 方 法 。 它 必 须 在 送 出 字 串 的 结 尾 。 例 如 , 这 个 程 序 hello

\d

延 迟 一 秒 钟 。 该 程 式 使 用 最 长 延 迟 为 一 秒 的 sleep(1) 。 ( 在 期 待 字 串 中 无 效 。 )
\K

插 入 一 个 中 断 ( 在 期 待 字 串 中 无 效 。 )

\n 送 出 一 个 新 列

(newline)或 换 行 (linefeed)字 元 。

\N 送 出 一 个 空 字

元 (null character)。 同 样 的 程 序 可 以 用 代 替 。 ( 在 期 待 字 串 中 无 效 。 )

\p

暂 停 一 小 段 时 间 。 延 迟 1/10 秒 。 ( 在 期 待 字 串 中 无 效 。 )
\q
抑 制 字 串 写 往 SYSLOG 档 案 。 该 ?????? 字 串 被 记 录 到 自 己 的 空 间 。 (

在 期 待 字 串 中 无 效 。 )

\r 传 送 或 期 待 一 个 机 架 返 回 ( 字 元 )

\s 代 替 字 串 中 的 空 白 。 这 个 可 以 用 在 不 愿 引 用 包 含 空 白 的 字 串 之 时 。

’HI

TIM’ 以 及 HI\sTIM 是 相 同 的 。

\t 传 送 或 期 待 一 个 定 位

(tab)字 元 。

\T

Send the phone number string as specified with the -T option (not valid in expect.)

\U

Send the phone number 2 string as specified with the -U option (not valid in expect.)

\\

传 送 或 期 待 一 个 倒 斜 线 (backslash)字 元 。
\ddd
将 八 进 位 数 字 (ddd) 折 叠 (collapse)成 单 一 的 ASCII 字 元 并 将 其 送

出 。 ( 某 些 字 元 在 期 待 字 串 中 无 效 。 )

^C 替 换 含 有 以

C 代 表 之 控 制 字 元 的 程 序 。 例 如 , 字 元 DC1(17) 是 以 ^Q

表 示 。 ( 某 些 字 元 在 期 待 字 串 中 无 效 。 )

ENVIRONMENT VARIABLES

Environment variables are available within chat scripts, if the -E option was specified in the command line. The metacharacter $ is used to introduce the name of the environment variable to substitute. If the substition fails, because the requested environment variable is not set, nothing is replaced for the variable.

TERMINATION CODES

The chat program will terminate with the following completion codes.

0

The normal termination of the program. This indicates that the script was executed without error to the normal conclusion.

1

One or more of the parameters are invalid or an expect string was too large for the internal buffers. This indicates that the program as not properly executed.

2

An error occurred during the execution of the program. This may be due to a read or write operation failing for some reason or chat receiving a signal such as SIGINT.

3

A timeout event occurred when there was an expect string without having a "-subsend" string. This may mean that you did not program the script correctly for the condition or that some unexpected event has occurred and the expected string could not be found.

4

The first string marked as an ABORT condition occurred.

5

The second string marked as an ABORT condition occurred.

6

The third string marked as an ABORT condition occurred.

7

The fourth string marked as an ABORT condition occurred.

...

The other termination codes are also strings marked as an ABORT condition.

Using the termination code, it is possible to determine which event terminated the script. It is possible to decide if the string "BUSY" was received from the modem as opposed to "NO DIAL TONE". While the first event may be retried, the second will probably have little chance of succeeding during a retry.

参 见 SEE ALSO

关 于 chat 指 令 稿 的 其 它 资 讯 可 以 在 UUCP 文 件 里 找 到 。 chat 指 令 稿 的 概 念 由 uucico 程 式 所 使 用 的 指 令 稿 来 的 。

uucico(1), uucp(1)

COPYRIGHT

The chat program is in public domain. This is not the GNU public license. If it breaks then you get to keep both pieces.

[中 文 版 维 护 人 ]

asdchen <asdchen [AT] pc2.net>

[中 文 版 最 新 更 新 ]

1995/09/30

《 中 国 linux论 坛 man手 册 翻 译 计 划 》 :

http://cmpp.linuxforum.net

本 页 面 中 文 版 由 中 文 man 手 册 页 计 划 提 供 。 中 文 man 手 册 页 计 划 : https://github.com/man-pages-zh/manpages-zh