sendCmd(n) 1.0 sendCmd "Send Command"

NAME

sendCmd - Send a command to be executed on a Cisco device.

SYNOPSIS

package require libcisco

sendCmd exec ?options? ?SessionId? Cmd
sendCmd global ?options? ?SessionId? Cmd
sendCmd line ?options? ?SessionId? Line Cmd
sendCmd interface ?options? ?SessionId? Interface Cmd

DESCRIPTION

The sendCmd command is used to send commands to be executed on a Cisco device. The following Cisco devices have been verified to work with sendCmd:

The first argument to sendCmd specifies the type of command to send to the target device. A list of valid types and their associated options is detailed below.

Note: Before making a call to sendCmd, a session must first be opened to the target device using the session open command.

sendCmd exec ?options? ?SessionId? Cmd
Sends a command from an EXEC prompt. For IOS based devices, this is used to send commands from a "user" or "privileged" EXEC prompt. For switches running Catalyst Code, this is used to send commands from "normal" and "privileged" mode. The command will be issued from an EXEC prompt at the current enable level.

Cmd is a command to be issued on the target device. SessionId should be explicitly specified if multiple sessions have been opened. If it is not, Cmd will be sent to the last session to be opened. The following options are supported:

-patlist PatList
-timeout Timeout {[0-9]+}
-- (end of options)

PatList is a pattern-action list following the convention required by the expect command from the Expect extension to Tcl written by Don Libes. The expect command is documented both on-line and in the O'Reilly book, Exploring Expect, by Don Libes. If no PatList is specified, only a minimal amount of error checking is performed. If PatList is set to the keyword nofeedback, then the expected result from issuing Cmd is nothing. In other words, after Cmd is issued, the device is expected to immediately display the next prompt with no feedback from the command. This is the norm when entering configuration commands on an IOS-based device.

Commands issued using sendCmd exec are expected to complete within 10 seconds by default. Completion is determined by matching a pattern, either a default pattern, or a pattern explicitly specified using the -patlist option. On high latency, heavily loaded, or unreliable WAN links, 10 seconds may not be a sufficient amount of time. The -timeout option may be used to specify a different timeout value.

On success, sendCmd exec returns the result of the command. On error, a short text message is returned beginning with the string "err".

sendCmd global ?options? ?SessionId? Cmd
Sends a command in global config mode.

Cmd is a command to be issued on the target device. SessionId should be explicitly specified if multiple sessions have been opened. If it is not, Cmd will be sent to the last session to be opened. The following option is supported:

-patlist PatList
-timeout Timeout {[0-9]+}
-- (end of options)

PatList is a pattern-action list following the convention required by the expect command from the Expect extension to Tcl written by Don Libes. The expect command is documented both on-line and in the O'Reilly book, Exploring Expect, by Don Libes. If no PatList is specified, only a minimal amount of error checking is performed. If PatList is the keyword nofeedback, then the expected result from issuing Cmd is nothing. In other words, after Cmd is issued, the device is expected to immediately display the next prompt with no feedback from the command.

Commands issued using sendCmd global are expected to complete within 10 seconds by default. Completion is determined by matching a pattern, either a default pattern, or a pattern explicitly specified using the -patlist option. On high latency, heavily loaded, or unreliable WAN links, 10 seconds may not be a sufficient amount of time. The -timeout option may be used to specify a different timeout value.

On success, sendCmd global returns the result of the command. On error, a short text message is returned beginning with the string "err".

sendCmd line ?options? ?SessionId? Line Cmd
Sends a command in line configuration mode.

Line is the line or range of lines to be configured. Line is in the format and syntax that would be expected by an IOS device to follow the "line" command from global config mode (e.g. "vty 0 4", "con 0", "1 5"). Cmd is a command to be issued on the target device. SessionId should be explicitly specified if multiple sessions have been opened. If it is not, Cmd will be sent to the last session to be opened. The following option is supported:

-patlist PatList
-timeout Timeout {[0-9]+}
-- (end of options)

PatList is a pattern-action list following the convention required by the expect command from the Expect extension to Tcl written by Don Libes. The expect command is documented both on-line and in the O'Reilly book, Exploring Expect, by Don Libes. If no PatList is specified, only a minimal amount of error checking is performed. If PatList is the keyword nofeedback, then the expected result from issuing Cmd is nothing. In other words, after Cmd is issued, the device is expected to immediately display the next prompt with no feedback from the command.

Commands issued using sendCmd line are expected to complete within 10 seconds by default. Completion is determined by matching a pattern, either a default pattern, or a pattern explicitly specified using the -patlist option. On high latency, heavily loaded, or unreliable WAN links, 10 seconds may not be a sufficient amount of time. The -timeout option may be used to specify a different timeout value.

On success, sendCmd line returns the result of the command. On error, a short text message is returned beginning with the string "err".

sendCmd interface ?options? ?SessionId? Interface Cmd
Sends a command in interface configuration mode.

Interface is the interface to be configured. Interface is in the format and syntax that would be expected by an IOS device to follow the "interface" command from global config mode (e.g. "ethernet0", "serial0/0"). Cmd is a command to be issued on the target device. SessionId should be explicitly specified if multiple sessions have been opened. If it is not, Cmd will be sent to the last session to be opened. The following option is supported:

-patlist PatList
-timeout Timeout {[0-9]+}
-- (end of options)

PatList is a pattern-action list following the convention required by the expect command from the Expect extension to Tcl written by Don Libes. The expect command is documented both on-line and in the O'Reilly book, Exploring Expect, by Don Libes. If no PatList is specified, only a minimal amount of error checking is performed. If PatList is the keyword nofeedback, then the expected result from issuing Cmd is nothing. In other words, after Cmd is issued, the device is expected to immediately display the next prompt with no feedback from the command.

Commands issued using sendCmd interface are expected to complete within 10 seconds by default. Completion is determined by matching a pattern, either a default pattern, or a pattern explicitly specified using the -patlist option. On high latency, heavily loaded, or unreliable WAN links, 10 seconds may not be a sufficient amount of time. The -timeout option may be used to specify a different timeout value.

On success, sendCmd interface returns the result of the command. On error, a short text message is returned beginning with the string "err".

EXAMPLE

The following code will open a session to 192.168.1.1, put the device in "enable" mode, save the output from a "show running-config" command to the variable Result, and turn off logging to the console. It will then close the session to the device.

session open 192.168.1.1 cisco
session enable san-fran
set Result [ sendCmd exec "show run" ]
sendCmd global "no logging console"
session close

SEE ALSO

session(n)

KEYWORDS

send, sendCmd, exec, global, line, interface