#!/usr/local/perl-5.8.0/bin/perl
use strict;
use threads;
use Expect;
sub mysub {
my $remoteshell;
unless ( $remoteshell = Expect -> spawn ("ssh2 192.168.1.1") ) {
die "error spawning";
}
$remoteshell -> log_stdout(1);
unless ( $remoteshell -> expect (120,
[ "ssword:" => sub {
$remoteshell -> send ("mypassword\n");
}
], ) ) {
die "no password prompt";
}
unless ( $remoteshell -> expect (20,"ro\@charon:") ) {
die "no prompt";
}
print $remoteshell "touch /tmp/hopo\n";
$remoteshell ->soft_close();
}
&mysub;
####
my $h = threads->new(\&mysub);
$h->join;
####
thread failed to start: no password prompt at ./expect.pl line 21.