After invoking the @login
command (and possibly @enable
as well), most scripts contain a sequence of Device commands that are sent to the device for execution. A typical Device command is shown below:
Device commands are executed as follows:
[last-words] shutdown { "Are you sure? ", "Y" }
The script sends the command text to the device. It terminates the command with CommandTerminator
.
If the command has a query, the device returns the query to the script. When it detects the query prompt, the script sends the query response to the device.
Next, the device executes the commands, and sends its output back to the script.
If the command's output is long enough to result in more prompts, when the script detects a MorePrompt
, it sends MoreResponse
to the device.
The script consumes the command's output until it detects CommandPrompt
, at which point it assumes that the command's output is complete.
If at any time the device's output stalls for more than Settings.ReadTimeout
, it is assumed that something is wrong, and the script returns failure.
If the command succeeds, and it has a KEY, its output is saved in the WhatsUp Gold database.
The following script is typical:
@login
enable { "password: ", "$(Settings.PrivilegedPassword)" }
[running-config] show run
[-] logout
This script first logs in with the @login command, then enters privileged mode with the @enable command.
Next, the script sends the show run
command to the device. The output of this command is saved in the WUG database under the running-config
key.
Finally, the script sends the logout
command to the device, at which point the device closes the network connection.
The [-] key on the logout
command tells WhatsConfigured not to expect any output from the command, because the command causes the device to close the network connection. Typically, receiving no output from a command indicates failure, but in the case of exit
or logout
commands (or any other command that closes the connection), a lack of output does not indicate failure. Script authors can use the [-] key to indicate such commands and prevent WhatsConfigured from returning failure when the device closes the connection.