sendCmd - send and execute a command
SYNOPSIS
package require libcisco
|
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.
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.
COMMANDS
Cmd is a command to be issued on the target device.
The following options are supported:
On success, sendCmd exec returns the result of the command.
On error, a short text message is returned beginning with the string "err".
Cmd is a command to be issued on the target device.
The following options are supported:
On success, sendCmd global returns the result of the command.
On error, a short text message is returned beginning with the string "err".
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:
On success, sendCmd line returns the result of the command.
On error, a short text message is returned beginning with the string "err".
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:
On success, sendCmd interface returns the result of the command.
On error, a short text message is returned beginning with the string "err".
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:
On success, sendCmd acl returns the result of the command.
On error, a short text message is returned beginning with the string "err".
EXAMPLE
#!/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 |