NAME
Mnet::Expect::Cli::Ios - Expect sessions to cisco ios devices
SYNOPSIS
# refer also to Mnet::Expect::Cli
use Mnet::Expect::Cli::Ios
# Mnet::Expect::Cli has example with ssh host/key checks disabled
my $expect = Mnet::Expect::Cli::Ios->new({
spawn => "ssh user@1.2.3.4", password_in => 1
});
# ensure we are in ios enable mode
$expect->enable() or die "enable failed";
# get output from command on connected ios device
my $output = $expect->command("show version");
# gracefully end/exit ios session
$expect->close;
DESCRIPTION
Mnet::Expect::Cli::Ios can be used to spawn Expect processes which can be used to programmatically control ssh or telnet command line user, enable, and config sessions to cisco ios and similar devices, with support for Mnet options, logging, caching, and testing.
Refer also to the Mnet::Expect and Mnet::Expect::Cli modules. The methods in those modules are inherited by objects created with this module.
METHODS
Mnet::Expect::Cli::Ios implements the methods listed below.
new
$expect = Mnet::Expect::Cli::Ios->new(\%opts)
This method can be used to create new Mnet::Expect::Cli::Ios objects.
The following input opts may be specified, in addition to options from the Mnet::Expect::Cli and Mnet::Expect modules:
enable set to password for enable mode during login
enable_in stderr prompt for stdin entry of enable if not set
enable_user default enable username set from username option
failed_re default recognizes lines starting w/ios % error char
paging_key default space key to send for ios pagination prompts
paging_re default recognizes ios pagination prompt --more--
prompt_re defaults for ios user or enable prompts, see below
An error is issued if there are login problems.
For example, the following call will start an ssh expect session to a device, with a prompt for password input if necessary:
# refer to SYNOPSIS example and Mnet::Expect::Cli for more info
my $expect = Mnet::Expect::Cli::Ios->new({
spawn => "ssh user@1.2.3.4", password_in => 1
});
Set failed_re to detect failed logins faster, as long as there's no conflict with text that appears in login banners. For example:
(?i)(^\s*%|closed|error|denied|fail|incorrect|invalid|refused|sorry)
A default prompt_re regex string for ios devices is used by this method to detect normal user and enable mode command prompts:
(^|\r|\n)\S+(>|#) ?(\r|\n|$)
The default ios prompt_re will be adjusted after login to work in various configuration modes where the prompt may be truncated with various suffixes applied. This adjustment is disabled if prompt_re exists as an input option to this function. Refer also to the Mnet::Expect::Cli module new method for more information on prompt_re.
Refer to the Mnet::Expect::Cli and Mnet::Expect modules for more information.
enable
$boolean = $expect->enable($password)
Use this method to check if an ios device session is currently in enable mode, and/or to enter enable mode on the device.
The input password argument will be used if there is an enable password prompt, otherwise the enable option set for the current object will be used, or the user will be prompted if the enable_in option is set.
A fatal error is issued if an enable password is required and none is set.
A value of true is returned if the ios device is at an enable mode command prompt, otherwise a value of false is returned.
close
$expect->close
This method sends the end and exit ios commands before closing the current expect session. Timeouts and disconnects are gracefully handled. Refer to the close method in the Mnet::Expect::Cli module for more information.
TESTING
Mnet::Test --record and --replay functionality are supported. Refer to the TESTING perldoc section of Mnet::Expect::Cli module for more information.