chat
No standard "chat" command exists in Linux
TLDR
Execute a chat script directly from the command line
Execute a chat script from a file
Set a custom timeout (in seconds) for expecting a response
Enable verbose output to log the conversation to syslog
Use a report file to log specific strings received during the conversation
Dial a phone number using a variable, substituting \T in the script
Include an abort condition if a specific string is received
SYNOPSIS
chat [options] [chat-script]
PARAMETERS
-v
Verbose mode: logs to standard output.
-V
Displays chat version information.
-E
Don't use stderr for logging output.
-T
Specifies the tty line to use.
-f
Specifies a file containing the chat script.
-s
Suppress diagnostic messages.
-S
Sets a timeout value for receiving characters.
-t
Sets overall timeout limit.
-q
Quiet mode.
-r
Don't strip CR from input.
''
Adds a
TIMEOUT
Set a timeout value in seconds, use in the chat script.
DESCRIPTION
The chat command is a versatile tool designed to automate interactions with modem-like devices or any process that communicates via serial lines. It reads a script containing expected input sequences and corresponding output strings, enabling automated dialing, login, and other command-line interactions with serial devices. Chat scripts often use string sequences which are interpreted by chat, which can send commands or strings in response to the incoming communication. Chat is especially useful to configure PPP (Point-to-Point Protocol) connections for dial-up internet access. It can be used to send AT commands to modems, handle responses, and initiate data transfer.
While powerful, using chat effectively requires a solid understanding of the target device's communication protocol and the intricacies of crafting appropriate chat scripts. Careful error handling and debugging are essential to ensure reliable operation. Its primary function is facilitating serial port communications based on pre-determined scripts, and may rely on external programs to start a PPP connection (e.g., pppd). It can also be useful for managing serial console connections to embedded devices.
CAVEATS
Careful scripting is critical to avoid infinite loops or unexpected behavior, especially with asynchronous serial communication. Correctly handle timeouts to avoid processes hanging indefinitely. Understanding the modem's AT command set is crucial for writing effective chat scripts.
CHAT SCRIPT SYNTAX
Chat scripts consist of pairs of expect-send sequences. EXPECT specifies the expected input from the serial device, and SEND defines the string to send in response. Special characters such as
(carriage return),
(newline), ""(empty string), and \ (escape) are used to represent non-printable characters or control sequences. The script is interpreted sequentially, with chat waiting for the expected input before sending the corresponding output. A script might look like this:
"" AT\r OK ATDT1234567\r CONNECT \c
ERROR HANDLING
It's important to handle potential errors within a chat script. You can include multiple expected responses for a single send command, allowing you to respond differently based on the received output. Use TIMEOUT option in the script to manage potentially infinite loops.
HISTORY
The chat command has been a component of many Linux distributions since the early days of dial-up networking. It evolved alongside the widespread adoption of PPP for internet connections, serving as a critical tool for automating modem initialization and authentication. Its design reflects the challenges of establishing reliable communication links over noisy analog telephone lines. As broadband connections became prevalent, the usage of chat declined, but it remains valuable for serial communication with embedded systems and legacy applications.