---
name: "Rex::Helper::SSH2::Expect"
section: "3pm"
platform: "linux"
package: "rex"
version: "1.16.0-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Rex::Helper::SSH2::Expect"
---

# Rex::Helper::SSH2::Expect(3pm)

An Expect like module for Net::SSH2

## NAME

Rex::Helper::SSH2::Expect - An Expect like module for Net::SSH2

## DESCRIPTION

This is a module to have expect like features for Net::SSH2. This is the first version of this module. Please report bugs at GitHub \<https://github.com/krimdomu/net-ssh2-expect\>

## DEPENDENCIES

- •

  Net::SSH2

## SYNOPSIS

```
 use Rex::Helper::SSH2::Expect;
 my $exp = Rex::Helper::SSH2::Expect->new($ssh2);
 $exp->spawn("passwd");
 $exp->expect($timeout, [
                  qr/Enter new UNIX password:/ => sub {
                                          my ($exp, $line) = @_;
                                          $exp->send($new_password);
                                        }
                ],
                [
                  qr/Retype new UNIX password:/ => sub {
                                          my ($exp, $line) = @_;
                                          $exp->send($new_password);
                                        }
                ],
                [
                  qr/passwd: password updated successfully/ => sub {
                                                  my ($exp, $line) = @_;
                                                  $exp->hard_close;
                                                }
                ]);
```

## CLASS METHODS

### new($ssh2)

Constructor: You need to parse an connected Net::SSH2 Object.

### log\_stdout(0\|1)

Log on STDOUT.

### log\_file($file)

Log everything to a file. `$file` can be a filename, a filehandle or a subRef.

### spawn($command, @parameters)

Spawn `$command` with `@parameters` as parameters.

### soft\_close()

Currently only an alias to **hard\_close()**;

### hard\_close();

Stops the execution of the process.

### expect($timeout, @match\_patters)

This method controls the execution of your process.

### send($string)

Send a string to the running command.
