#! /usr/bin/perl use strict; use warnings; use Net::OpenSSH; use Expect; use IO::Stty; use Creds qw($user $pass $enpass); my $host = $ARGV[0]; my $timeout = 5; my $ssh = Net::OpenSSH->new("$user:$pass\@$host", timeout => 10); $ssh->error and die "unable to connect to host: ". $ssh->error; my ($pty, $pid) = $ssh->open2pty(); my $expect = Expect->init($pty); $expect->expect($timeout, [ '>' => sub { $expect->send('enable'); $expect->send("\r"); $expect->expect('Password:'); $expect->send($enpass); $expect->send("\r") ; } ], [ '#' ], ); $expect->interact();