in reply to Collecting output from Expect
This example expects the prompt of a host to end on '$ ' (DollarSpace), you might have a diffrent prompt(especially if the HPux box uses csh, then it's usually '> '). Hope this helps. Cheers Rolanduse strict; use warnings; use Expect; my $timeout = 5; my $command = '/usr/bin/ssh'; my $user='johndoe'; my $host='192.168.47.11'; my $password = 'godsexpower'; my $exp = Expect->spawn($command, "$user\@$host") or die "Cannot spawn $command: $!\n"; $exp->expect($timeout, [ qr{password:} , sub {$exp->send("$password\n" +)} ]); $exp->expect($timeout, [ qr{\$ } , sub {$exp->send("ls\n")} ]); $exp->expect($timeout, [ qr{\n*?\$ } , sub {print "got the output: '". + $exp->before()."'\n"} ]); $exp->soft_close();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Collecting output from Expect
by paranoid times (Acolyte) on Oct 18, 2007 at 04:26 UTC |