$exp->expect($timeout,
[ qr/\(yes\/no\)\?/i, sub { my $self = shift;
$self->send("yes\r"); <----unknown host
exp_continue; }],
[ qr/password: /i, sub { my $self = shift;
$self->send("$password\n"); <------ needs password
exp_continue; }],
[ qr/#/i, sub { my $self = shift; <-------- ready to go.
$self->send("ls\n");
;
}],
);
####
$exp->expect($timeout,
[ qr/#/i, sub { my $self = shift;
$self->send("ll\n"); <---- only works when I have a line below (crazy that is how I know this is not right)
;
}], unless ($exp->expect($timeout, -re , "~")){} ;
);
####
#!/usr/bin/env perl
use strict;
use warnings;
use Expect;
#$Expect::Exp_Internal = 1;
my $command = "ssh";
my $user = "root";
my @ips = ("10.16.135.157");
my $cnt= 0+@ips;
my $password = "aristo1";
my $timeout = 10;
for (my $i =0; $i < $cnt; $i++) {
my $exp = Expect->spawn ($command, "$user"."@"."$ips[$i]");
#$exp->debug(2);
$exp->expect($timeout,
[ qr/\(yes\/no\)\?/i, sub { my $self = shift;
$self->send("yes\r");
exp_continue; }],
[ qr/password: /i, sub { my $self = shift;
$self->send("$password\n");
exp_continue; }],
[ qr/#/i, sub { my $self = shift;
$self->send("ls\n");
;
}],
);
$exp->expect($timeout,
[ qr/#/i, sub { my $self = shift;
$self->send("ll\n");
;
}],
);
unless ($exp->expect($timeout, -re , "~")){} ;
# $exp->send("time\n");
}