⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chat.8

📁 经典的ppp程序
💻 8
📖 第 1 页 / 共 2 页
字号:
.\" -*- nroff -*-.\" manual page [] for chat 1.8.\" $Id: chat.8,v 1.9 1999/09/06 05:10:23 paulus Exp $.\" SH section heading.\" SS subsection heading.\" LP paragraph.\" IP indented paragraph.\" TP hanging label.TH CHAT 8 "22 May 1999" "Chat Version 1.22".SH NAMEchat \- Automated conversational script with a modem.SH SYNOPSIS.B chat[.I options].I script.SH DESCRIPTION.LPThe \fIchat\fR program defines a conversational exchange between thecomputer and the modem. Its primary purpose is to establish theconnection between the Point-to-Point Protocol Daemon (\fIpppd\fR) andthe remote's \fIpppd\fR process..SH OPTIONS.TP.B -f \fI<chat file>Read the chat script from the chat \fIfile\fR. The use of this optionis mutually exclusive with the chat script parameters. The user musthave read access to the file. Multiple lines are permitted in thefile. Space or horizontal tab characters should be used to separatethe strings..TP.B -t \fI<timeout>Set the timeout for the expected string to be received. If the stringis not received within the time limit then the reply string is notsent. An alternate reply may be sent or the script will fail if thereis no alternate reply string. A failed script will cause the\fIchat\fR program to terminate with a non-zero error code..TP.B -r \fI<report file>Set the file for output of the report strings. If you use the keyword\fIREPORT\fR, the resulting strings are written to this file. If thisoption is not used and you still use \fIREPORT\fR keywords, the\fIstderr\fR file is used for the report strings..TP.B -eStart with the echo option turned on. Echoing may also be turned onor off at specific points in the chat script by using the \fIECHO\fRkeyword. When echoing is enabled, all output from the modem is echoedto \fIstderr\fR..TP.B -EEnables environment variable substituion within chat scripts using thestandard \fI$xxx\fR syntax..TP.B -vRequest that the \fIchat\fR script be executed in a verbose mode. The\fIchat\fR program will then log the execution state of the chatscript as well as all text received from the modem and the outputstrings sent to the modem.  The default is to log through the SYSLOG;the logging method may be altered with the -S and -s flags..TP.B -VRequest that the \fIchat\fR script be executed in a stderr verbosemode. The \fIchat\fR program will then log all text received from themodem and the output strings sent to the modem to the stderr device. Thisdevice is usually the local console at the station running the chat orpppd program..TP.B -sUse stderr.  All log messages from '-v' and all error messages will besent to stderr..TP.B -SDo not use the SYSLOG.  By default, error messages are sent to theSYSLOG.  The use of -S will prevent both log messages from '-v' anderror messages from being sent to the SYSLOG..TP.B -T \fI<phone number>Pass in an arbitary string, usually a phone number, that will besubstituted for the \\T substitution metacharacter in a send string..TP.B -U \fI<phone number 2>Pass in a second string, usually a phone number, that will besubstituted for the \\U substitution metacharacter in a send string.This is useful when dialing an ISDN terminal adapter that requires two numbers..TP.B scriptIf the script is not specified in a file with the \fI-f\fR option thenthe script is included as parameters to the \fIchat\fR program..SH CHAT SCRIPT.LPThe \fIchat\fR script defines the communications..LPA 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:.IPogin:-BREAK-ogin: ppp ssword: hello2u2.LPThis line indicates that the \fIchat\fR program should expect the string"ogin:". If it fails to receive a login prompt within the time intervalallotted, it is to send a break sequence to the remote and then expect thestring "ogin:". If the first "ogin:" is received then the break sequence isnot generated..LPOnce it received the login prompt the \fIchat\fR program will send thestring ppp and then expect the prompt "ssword:". When it receives theprompt for the password, it will send the password hello2u2..LPA carriage return is normally sent following the reply string. It is notexpected in the "expect" string unless it is specifically requested by usingthe \\r character sequence..LPThe expect sequence should contain only what is needed to identify thestring. Since it is normally stored on a disk file, it should not containvariable information. It is generally not acceptable to look for timestrings, network identification strings, or other variable pieces of data asan expect string..LPTo help correct for characters which may be corrupted during the initialsequence, look for the string "ogin:" rather than "login:". It is possiblethat the leading "l" character may be received in error and you may neverfind the string even though it was sent by the system. For this reason,scripts look for "ogin:" rather than "login:" and "ssword:" rather than"password:"..LPA very simple script might look like this:.IPogin: ppp ssword: hello2u2.LPIn other words, expect ....ogin:, send ppp, expect ...ssword:, send hello2u2..LPIn actual practice, simple scripts are rare. At the vary least, youshould include sub-expect sequences should the original string not bereceived. For example, consider the following script:.IPogin:--ogin: ppp ssword: hello2u2.LPThis would be a better script than the simple one used earlier. This would lookfor the same login: prompt, however, if one was not received, a singlereturn sequence is sent and then it will look for login: again. Should linenoise obscure the first login prompt then sending the empty line willusually generate a login prompt again..SH COMMENTSComments can be embedded in the chat script. A comment is a line whichstarts with the \fB#\fR (hash) character in column 1. Such commentlines are just ignored by the chat program. If a '#' character is tobe expected as the first character of the expect sequence, you shouldquote 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:.IP# Now wait for the prompt and send logout string.br\'# ' logout.LP.SH SENDING DATA FROM A FILEIf the string to send starts with an at sign (@), the rest of thestring is taken to be the name of a file to read to get the string tosend.  If the last character of the data read is a newline, it isremoved.  The file can be a named pipe (or fifo) instead of a regularfile.  This provides a way for \fBchat\fR to communicate with anotherprogram, for example, a program to prompt the user and receive apassword typed in..LP.SH ABORT STRINGSMany modems will report the status of the call as a string. Thesestrings may be \fBCONNECTED\fR or \fBNO CARRIER\fR or \fBBUSY\fR. Itis often desirable to terminate the script should the modem fail toconnect to the remote. The difficulty is that a script would not knowexactly which modem string it may receive. On one attempt, it mayreceive \fBBUSY\fR while the next time it may receive \fBNO CARRIER\fR..LPThese "abort" strings may be specified in the script using the \fIABORT\fRsequence. It is written in the script as in the following example:.IPABORT BUSY ABORT 'NO CARRIER' '' ATZ OK ATDT5551212 CONNECT.LPThis sequence will expect nothing; and then send the string ATZ. Theexpected response to this is the string \fIOK\fR. When it receives \fIOK\fR,the string ATDT5551212 to dial the telephone. The expected string is\fICONNECT\fR. If the string \fICONNECT\fR is received the remainder of thescript is executed. However, should the modem find a busy telephone, it willsend the string \fIBUSY\fR. This will cause the string to match the abortcharacter sequence. The script will then fail because it found a match tothe abort string. If it received the string \fINO CARRIER\fR, it will abortfor the same reason. Either string may be received. Either string willterminate the \fIchat\fR script..SH CLR_ABORT STRINGSThis sequence allows for clearing previously set \fBABORT\fR strings.\fBABORT\fR strings are kept in an array of a pre-determined size (atcompilation time); \fBCLR_ABORT\fR will reclaim the space for clearedentries so that new strings can use that space..SH SAY STRINGSThe \fBSAY\fR directive allows the script to send strings to the userat the terminal via standard error.  If \fBchat\fR is being run bypppd, and pppd is running as a daemon (detached from its controllingterminal), standard error will normally be redirected to the file/etc/ppp/connect-errors..LP\fBSAY\fR strings must be enclosed in single or double quotes. Ifcarriage return and line feed are needed in the string to be output,you must explicitely add them to your string..LPThe SAY strings could be used to give progress messages in sections ofthe script where you want to have 'ECHO OFF' but still let the userknow what is happening.  An example is:.IPABORT BUSY .brECHO OFF .brSAY "Dialling your ISP...\\n" .br\'' ATDT5551212 .brTIMEOUT 120.brSAY "Waiting up to 2 minutes for connection ... ".brCONNECT '' .brSAY "Connected, now logging in ...\n".brogin: account.brssword: pass.br$ \cSAY "Logged in OK ...\n"\fIetc ...\fR.LPThis sequence will only present the SAY strings to the user and allthe details of the script will remain hidden. For example, if theabove script works, the user will see:.IPDialling your ISP....brWaiting up to 2 minutes for connection ... Connected, now logging in ....brLogged in OK ....LP.SH REPORT STRINGSA \fBreport\fR string is similar to the ABORT string. The differenceis that the strings, and all characters to the next control charactersuch as a carriage return, are written to the report file..LPThe report strings may be used to isolate the transmission rate of themodem's connect string and return the value to the chat user. Theanalysis of the report string logic occurs in conjunction with theother string processing such as looking for the expect string. The useof the same string for a report and abort sequence is probably notvery useful, however, it is possible.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -