MAN page from Old RedHat 5.X ppp-2.3.3-4.i386.rpm
CHAT
Section: Maintenance Commands (8)
Updated: 27 Sep 1997
Index NAME
chat - Automated conversational script with a modem
SYNOPSIS
chat[
options]
script DESCRIPTION
The chat program defines a conversational exchange between thecomputer and the modem. Its primary purpose is to establish theconnection between the Point-to-Point Protocol Daemon (pppd) andthe remote's pppd process.
OPTIONS
- -f <chat file>
- Read the chat script from the chat file. 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.
- -t <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 thechat program to terminate with a non-zero error code.
- -r <report file>
- Set the file for output of the report strings. If you use the keywordREPORT, the resulting strings are written to this file. If thisoption is not used and you still use REPORT keywords, thestderr file is used for the report strings.
- -e
- Start with the echo option turned on. Echoing may also be turned onor off at specific points in the chat script by using the ECHOkeyword. When echoing is enabled, all output from the modem is echoedto stderr.
- -v
- Request that the chat script be executed in a verbose mode. Thechat 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.
- -V
- Request that the chat script be executed in a stderr verbosemode. The chat 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. This option will not work properly if the stderr isredirected to the /dev/null location as is the case should pppd be runin the 'detached' mode. In that case, use the '-v' option to recordthe session on the SYSLOG device.
- -s
- Use stderr. All log messages from '-v' and all error messages will besent to stderr.
- -S
- Do 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.
- -T <phone number>
- Pass in an arbitary string, usually a phone number, that will besubstituted for the \T substitution metacharacter in a send string.
- -U <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.
- script
- If the script is not specified in a file with the -f option thenthe script is included as parameters to the chat program.
CHAT SCRIPT
The chat script defines the 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:
- ogin:-BREAK-ogin: ppp ssword: hello2u2
This line indicates that the chat 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.
Once it received the login prompt the chat program will send thestring ppp and then expect the prompt "ssword:". When it receives theprompt for the password, it will send the password hello2u2.
A 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.
The 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.
To 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:".
A very simple script might look like this:
- ogin: ppp ssword: hello2u2
In other words, expect ....ogin:, send ppp, expect ...ssword:, send hello2u2.
In 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:
- ogin:--ogin: ppp ssword: hello2u2
This 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.
COMMENTS
Comments can be embedded in the chat script. A comment is a line whichstarts with the
# (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:
- # Now wait for the prompt and send logout string
'# ' logout
ABORT STRINGS
Many modems will report the status of the call as a string. Thesestrings may be
CONNECTED or
NO CARRIER or
BUSY. 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
BUSY while the next time it may receive
NO CARRIER.
These "abort" strings may be specified in the script using the ABORTsequence. It is written in the script as in the following example:
- ABORT BUSY ABORT 'NO CARRIER' '' ATZ OK ATDT5551212 CONNECT
This sequence will expect nothing; and then send the string ATZ. Theexpected response to this is the string OK. When it receives OK,the string ATDT5551212 to dial the telephone. The expected string isCONNECT. If the string CONNECT is received the remainder of thescript is executed. However, should the modem find a busy telephone, it willsend the string BUSY. 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 NO CARRIER, it will abortfor the same reason. Either string may be received. Either string willterminate the chat script.
CLR_ABORT STRINGS
This sequence allows for clearing previously set
ABORT strings.
ABORT strings are kept in an array of a pre-determined size (atcompilation time);
CLR_ABORT will reclaim the space for clearedentries so that new strings can use that space.
SAY STRINGS
The
SAY directive allows the script to send strings to the userat the terminal via standard error. If
chat 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.
SAY 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.
The 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:
- 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 ...
ogin: account
ssword: pass
$ SAY "Logged in OK ...etc ...
This 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:
- 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 differenceis that the strings, and all characters to the next control charactersuch as a carriage return, are written to the report file.
The 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.
The report strings to no change the completion code of the program.
These "report" strings may be specified in the script using the REPORTsequence. 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 stringATDT5551212 to dial the telephone. The expected string isCONNECT. If the string CONNECT is received the remainderof the script is executed. In addition the program will write to theexpect-file the string "CONNECT" plus any characters which follow itsuch 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 (atcompilation time);
CLR_REPORT will reclaim the space for clearedentries so that new strings can use that space.
ECHO
The echo options controls whether the output from the modem is echoedto
stderr. This option may be set with the
-e option, butit can also be controlled by the
ECHO keyword. The "expect-send"pair
ECHO ON enables echoing, and
ECHO OFFdisables it. With this keyword you can select which parts of theconversation should be visible. For instance, with the followingscript:
- ABORT 'BUSY'
ABORT 'NO CARRIER'
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, everythingwill be echoed.
HANGUP
The HANGUP options control whether a modem hangup should be consideredas an error or not. This option is useful in scripts for diallingsystems which will hang up and call your system back. The HANGUPoptions can be
ON or
OFF.
When HANGUP is set OFF and the modem hangs up (e.g., after the firststage of logging in to a callback system),
chat will continuerunning the script (e.g., waiting for the incoming call and secondstage login prompt). As soon as the incoming call is connected, youshould use the
HANGUP ON directive to reinstall normal hang upsignal behavior. Here is an (simple) example script:
- ABORT 'BUSY'
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
The initial timeout value is 45 seconds. This may be changed using the
-tparameter.
To change the timeout value for the next expect string, the followingexample may be used:
- ATZ OK ATDT5551212 CONNECT TIMEOUT 10 ogin:--ogin: TIMEOUT 5 assword: hello2u2
This will change the timeout to 10 seconds when it expects the login:prompt. The timeout is then changed to 5 seconds when it looks for thepassword prompt.
The timeout, once changed, remains in effect until it is changed again.
SENDING EOT
The special reply string of
EOT indicates that the chat programshould send an EOT character to the remote. This is normally theEnd-of-file character sequence. A return character is not sentfollowing the EOT.The EOT sequence may be embedded into the send string using thesequence
^D.
GENERATING BREAK
The special reply string of
BREAK will cause a break conditionto be sent. The break is a special signal on the transmitter. Thenormal processing on the receiver is to change the transmission rate.It may be used to cycle through the available transmission rates onthe remote until you are able to receive a valid login prompt.The break sequence may be embedded into the send string using the
\K sequence.
ESCAPE SEQUENCES
The expect and reply strings may contain escape sequences. All of thesequences are legal in the reply string. Many are legal in the expect.Those which are not valid in the expect sequence are so indicated.
- ''
- Expects or sends a null string. If you send a null string then it will stillsend the return character. This sequence may either be a pair of apostropheor quote characters.
- \\b
- represents a backspace character.
- \\c
- Suppresses the newline at the end of the reply string. This is the onlymethod to send a string without a trailing return character. It mustbe at the end of the send string. For example,the sequence hello\c will simply send the characters h, e, l, l, o.(not valid in expect.)
- \\d
- Delay for one second. The program uses sleep(1) which will delay to amaximum of one second.(not valid in expect.)
- \\K
- Insert a BREAK(not valid in expect.)
- \\n
- Send a newline or linefeed character.
- \\N
- Send a null character. The same sequence may be represented by \0.(not valid in expect.)
- \\p
- Pause for a fraction of a second. The delay is 1/10th of a second.(not valid in expect.)
- \\q
- Suppress writing the string to the SYSLOG file. The string ?????? iswritten to the log in its place.(not valid in expect.)
- \\r
- Send or expect a carriage return.
- \\s
- Represents a space character in the string. This may be used when itis not desirable to quote the strings which contains spaces. Thesequence 'HI TIM' and HI\sTIM are the same.
- \\t
- Send or expect a tab character.
- \\\\
- Send or expect a backslash character.
- \\ddd
- Collapse the octal digits (ddd) into a single ASCII character and send thatcharacter.(some characters are not valid in expect.)
- ^C
- 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.)
TERMINATION CODES
The
chat program will terminate with the following completioncodes.
- 0
- The normal termination of the program. This indicates that the scriptwas executed without error to the normal conclusion.
- 1
- One or more of the parameters are invalid or an expect string was toolarge for the internal buffers. This indicates that the program as notproperly executed.
- 2
- An error occurred during the execution of the program. This may be dueto a read or write operation failing for some reason or chat receivinga signal such as SIGINT.
- 3
- A timeout event occurred when there was an expect string withouthaving a "-subsend" string. This may mean that you did not program thescript correctly for the condition or that some unexpected event hasoccurred 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 ABORTcondition.
Using the termination code, it is possible to determine which eventterminated the script. It is possible to decide if the string "BUSY"was received from the modem as opposed to "NO DIAL TONE". While thefirst event may be retried, the second will probably have littlechance of succeeding during a retry.
SEE ALSO
Additional information about
chat scripts may be found with UUCPdocumentation. The
chat script was taken from the ideas proposedby the scripts used by the
uucico program.
uucico(1), uucp(1)
COPYRIGHT
The
chat program is in public domain. This is not the GNU publiclicense. If it breaks then you get to keep both pieces.
Index
- NAME
- SYNOPSIS
- DESCRIPTION
- OPTIONS
- CHAT SCRIPT
- COMMENTS
- ABORT STRINGS
- CLR_ABORT STRINGS
- SAY STRINGS
- REPORT STRINGS
- CLR_REPORT STRINGS
- ECHO
- HANGUP
- TIMEOUT
- SENDING EOT
- GENERATING BREAK
- ESCAPE SEQUENCES
- TERMINATION CODES
- SEE ALSO
- COPYRIGHT
This document was created byman2html,using the manual pages.