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]
chat [options] script
Read the chat script from the chat file. This option is mutually exclusive with the chat script parameters. You must have read access to use the file. Multiple lines are permitted in the file. Use the space or horizontal tab characters to separate the strings.
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 chat script fails. A failed script will cause the chat program to terminate with a non-zero error code.
Set the file for output of the report strings. If you use the keyword REPORT, the resulting strings are written to this file. If the -r option is not used and you use the REPORT keyword, the stderr file is used for the report strings.
Start with the echo option turned on. You turn echo on or off at specific points in the chat script using the ECHO keyword. When echoing is enabled, all output from the modem is echoed to stderr.
Enables environment variable substitution within chat scripts using the standard $xxx syntax.
Request that the chat script execute in a verbose mode. The chat program logs the execution state of the chat script as well as all text received from the modem and output strings sent to the modem. The default is to log through syslog(3C) with facility local2; the logging method is alterable using the -S and -s options.
Request that the chat script be executed in a stderr verbose mode. The chat program logs all text received from the modem and output strings sent to the modem to stderr. stderr is usually the local console at the station running the chat or pppd program.
Use stderr. Log messages from -v and error messages are sent to stderr.
Do not use syslog. By default, error messages are set to syslog. This option prevents log messages from -v and error messages from being sent to syslog.
Pass in an arbitrary string (usually a telephone number) that will be substituted for the \eT substitution metacharacter in a send string.
Pass in a second string (usually a telephone number) that will be substituted for the \eU substitution metacharacter in a send string. This is useful when dialing an ISDN terminal adapter that requires two numbers.
If the script is not specified in a file with the -f option, the script is included as parameters to the chat program.
ogin:-BREAK-ogin: ppp ssword: hello2u2
The example indicates that the chat 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.
Upon receiving the login prompt, the chat program sends the string "ppp" and then expects the prompt "ssword:". When the password prompt is received, it sends the password hello2u2.
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 \er character sequence.
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.
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:".
An example of a simple script follows:
ogin: ppp ssword: hello2u2
The example can be interpreted as: expect ogin:, send ppp, expect ...ssword:, send hello2u2.
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:
ogin:--ogin: ppp ssword: hello2u2
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.
# Now wait for the prompt and send logout string '# ' logout
ABORT BUSY ABORT 'NO CARRIER' '' ATZ OK ATDT5551212 CONNECT
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.
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.
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:
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"
This sequence hides script detail while presenting the SAY string to the user. In this case, you will see:
Dialing your ISP... Waiting up to 2 minutes for connection...Connected, now logging in... Logged in OK ...
REPORT strings can be used to isolate a modem's transmission rate from its CONNECT string and return the value to the chat 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.
Report strings may be specified in the script using the REPORT sequence. For example:
REPORT CONNECT ABORT BUSY ATDT5551212 CONNECT ogin: account
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 -r) in addition to any characters that follow.
ABORT 'BUSY' ABORT 'NO CARRIER' "" AT&F OK\er\en ATD1234567 \er\en \ec ECHO ON CONNECT \ec ogin: account
All output resulting from modem configuration and dialing is not visible, but output is echoed beginning with the CONNECT (or BUSY) message.
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
To change the timeout value for the next expect string, the following example can be used:
''"AT&F OK ATDT5551212 CONNECT \ec TIMEOUT 10 ogin:--ogin: username TIMEOUT 5 assword: hello2u2
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.
Once changed, the timeout value remains in effect until it is changed again.
Expects or sends a null string. If you send a null string, chat sends the return character. If you expect a null string, chat proceeds to the reply string without waiting. This sequence can be a pair of apostrophes or quote mark characters.
Represents a backspace character.
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.)
Delay for one second. The program uses sleep(1) which delays to a maximum of one second. (Not valid in expect.)
Insert a BREAK. (Not valid in expect.)
Send a newline or linefeed character.
Send a null character. The same sequence may be represented by \e0. (Not valid in expect.)
Pause for 1/10th of a second. (Not valid in expect.)
Suppress writing the string to syslog. The string ?????? is written to the log in its place. (Not valid in expect.)
Send or expect a carriage return.
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.
Send or expect a tab character.
Send the phone number string as specified with the -T option. (Not valid in expect.)
Send the phone number 2 string as specified with the -U option. (Not valid in expect.)
Send or expect a backslash character.
Collapse the octal digits (ddd) into a single ASCII character and send that character. (\e000 is not valid in an expect string.)
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.)
Normal program termination. Indicates that the script was executed without error to normal conclusion.
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.
An error occurred during the execution of the program. This may be due to a read or write operation failing or chat receiving a signal such as SIGINT.
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.
The first string marked as an ABORT condition occurred.
The second string marked as an ABORT condition occurred.
The third string marked as an ABORT condition occurred.
The fourth string marked as an ABORT condition occurred.
The other termination codes are also strings marked as an ABORT condition.
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.
ATTRIBUTE TYPE ATTRIBUTE VALUE |
Interface Stability Evolving |
Additional information on chat scripts are available with UUCP documentation. The chat script format was taken from scripts used by the uucico program.