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 command line sessions to cisco ios devices, with support for Mnet options, logging, caching, and testing.
Refer to the perl Expect module for more information. Also refer to the Mnet::Expect and Mnet::Expect::Cli modules.
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 to ios user or enable mode prompts
An error is issued if there are login problems.
For example, the following call will start an ssh expect session to a device with host key checking disabled:
# 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)
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 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.