Mnet::Expect::Cli::Ios - Expect sessions to cisco ios devices


    my $opts = { spawn => "ssh", prompt => 1 };
    my $expect = Mnet::Expect::Cli->new($opts);

    $expect->enable($password) or die "enable failed";

    my $output = $expect->command("show version");



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::Expct and Mnet::Expct::Cli modules.


Mnet::Expect::Cli::Ios implements the methods listed below.


    $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 prompt

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:

    my @spawn = qw(ssh);
    push @spawn, qw(-o StrictHostKeyChecking=no);
    push @spawn, qw(-o UserKnownHostsFile=/dev/null);
    push @spawn, qw(;
    my $opts = { spawn => \@spawn };
    my $expect = Mnet::Expect::Cli->new($opts);

Set failed_re to detect failed logins faster, as long as there's no conflict with text that appears in login banners. For example:


Refer to the Mnet::Expect::Cli and Mnet::Expect modules for more information.


    $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 will be used, or the enable and enable_in options for the current object. An error results if a password is needed and none was 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.



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 module for more information.


Mnet::Test --record and --replay functionality are supported. Refer to the TESTING perldoc section of Mnet::Expect::Cli module for more information.