NAME

Mnet::Expect - Create Expect objects with Mnet::Log support

SYNOPSIS

    use Mnet::Expect;

    my $expect = Mnet::Expect->new({ spawn => [qw(
        ssh
         -o StrictHostKeyChecking=no
         -o UserKnownHostsFile=/dev/null
         1.2.3.4
    )]});

    $expect->send("ls\r");

    $expect->close;

DESCRIPTION

Mnet::Expect can be used to spawn Expect processes, which can be used to programmatically control interactive terminal sessions, with support for Mnet options and logging.

Refer to the perl Expect module for more information. Also refer to the Mnet::Expct::Cli and Mnet::Expct::Cli::Ios modules.

METHODS

Mnet::Expect implements the methods listed below.

new

    $expect = Mnet::Expect->new(\%opts)

This method can be used to create new Mnet::Expect objects.

The following input opts may be specified:

    log_id      refer to perldoc Mnet::Log new method
    raw_pty     can be set 0 or 1, refer to perldoc Expect
    spawn       command and args array ref, or space separated string
    winsize     specify session rows and columns, default 99999x999

An error is issued if there are spawn problems.

For example, the following will spawn an telnet expect session to a device:

    my $expect = Mnet::Expect->new({ spawn => "telnet 1.2.3.4" });

Note that all connected session activity is logged for debugging, refer to the Mnet::Log module for more information.

close

    $expect->close

Attempt to call hard_close for the current Mnet::Expect objects Expect session, and send a kill signal if the process still exists.

The Expect object associated with the current Mnet::Expect object will be set to undefined. Refer also to the expect method documented below.

expect

    $expect->expect

Returns the underlying expect object used by this module, for access to fetures that may not be supported directly by Mnet::Expect modules. Refer to the Expect module for more information.

TESTING

Mnet::Expect does not include iteself include support for Mnet::Test functionality. This is a low level module that spawns expect sessions but does not know how to talk to devices. Any desired test fucntionality would need to be provided by the calling script.

SEE ALSO

Expect

Mnet

Mnet::Expect::Cli

Mnet::Expect::Cli::Ios

Mnet::Log

Mnet::Opts::Cli

Mnet::Test