@read
- Last Updated: July 8, 2022
- 2 minute read
- WhatsUp Gold
- Version 2026
- Version 2025
- Version 2024
- Version 2023.1
The @read command can be used by scripts to read the output coming back from the device. Typically, a call to @read immediately follows a call to @write. When calling @read, scripts can specify one or more patterns (i.e., strings or regular expressions) to help @read detect the end of the device output. @read assumes that device output is complete when either: the output matches one of the specified patterns, or no new output is received from the device for ReadTimeout seconds. Often, the output ends with CommandPrompt, so "@read $(CommandPrompt)" is a common way to call @read. If desired, the output received from the device can be stored in the database, as shown below:
@write "show run"
@write $(CommandTerminator)
[running-config, trim-end-lines = 1] @read $(CommandPrompt)
When executed, @read reads whatever output comes back from the device. If the output matches one of the specified patterns, the command succeeds. If the output received from the device does not match one of the specified patterns, the command fails (as well as the entire script).
If no patterns are specified (as shown below), @read returns whatever output comes back from the device. In this case, the command succeeds as long as the connection to the device is still open.
@read-more
Some devices return paged output that requires more prompts. If a script needs to handle more prompts during a read operation, it can use the @read-more command instead of @read. @read-more works just like @read, except that it handles more prompts during the reading process, while @read does not. Specifically, if MorePrompt is detected during the reading process, @read-more will send MoreResponse to the device.