sendCmd(n) 1.3 sendCmd "Send Command"

NAME

sendCmd - send and execute a command

SYNOPSIS

package require libcisco

sendCmd exec ?options? Cmd
sendCmd global ?options? Cmd
sendCmd line ?options? Line Cmd
sendCmd interface ?options? Interface Cmd
sendCmd acl ?options? Protocol Type Acl Cmd

DESCRIPTION

The sendCmd command is used to send commands to be executed on a Cisco network device. 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. The following devices have been verified to work with sendCmd:

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

COMMANDS

sendCmd exec ?options? 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.

The following options are supported:

-patlist PatList
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.

-timeout [0-9]+
By default, commands are expected to complete within 10 seconds. This option is used to override that default. The timeout value is measured in seconds. The value supplied must be an integer.

--
End of options.


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? Cmd
Sends a command in global config mode.

Cmd is a command to be issued on the target device.

The following options are supported:

-patlist PatList
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.

-timeout [0-9]+
By default, commands are expected to complete within 10 seconds. This option is used to override that default. The timeout value is measured in seconds. The value supplied must be an integer.

--
End of options.


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? 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"). You may need to enclose Line within quotes as it will almost always have a space in the value (see example below).

Cmd is a command to be issued on the target device.

The following options are supported:

-patlist PatList
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.

-timeout [0-9]+
By default, commands are expected to complete within 10 seconds. This option is used to override that default. The timeout value is measured in seconds. The value supplied must be an integer.

--
End of options.


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? 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.

The following options are supported:

-patlist PatList
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.

-timeout [0-9]+
By default, commands are expected to complete within 10 seconds. This option is used to override that default. The timeout value is measured in seconds. The value supplied must be an integer.

--
End of options.


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

sendCmd acl ?options? Protocol Type Acl Cmd
Sends a command in access-list configuration mode.

Protocol is the network layer protocol. Valid options are "ip" and "ipx".

Type is the type of access-list. Valid options for ip are "standard" and "extended". Valid options for ipx are "standard", "extended", and "sap".

Cmd is a command to be issued in access-list configuration mode.

The following options are supported:

-patlist PatList
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.

-timeout [0-9]+
By default, commands are expected to complete within 10 seconds. This option is used to override that default. The timeout value is measured in seconds. The value supplied must be an integer.

--
End of options.


On success, sendCmd acl 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 version" command to the variable Version, turn off logging to the console, and set the console line password to cisco. It will then close the session to the device.

 
#!/bin/sh
# the next line restarts using the tclsh interpreter \ 
exec tclsh "$0" "$@"

package require libcisco
namespace import libcisco::*

session open 192.168.1.1 cisco
session enable san-fran
set Version [ sendCmd exec "show version" ]
sendCmd global "no logging console"
sendCmd line "con 0" "password cisco"
session close

AUTHOR

Andy Ziegelbein <
mailto:aziegelb@users.sourceforge.net>

SEE ALSO

session(n), ezdo(n), ezget(n), ezset(n)

KEYWORDS

send, sendCmd, exec, global, line, interface