From: Matt Z. <mzagrabe@d.umn.edu> - 2015-03-26 20:47:52
|
On Thu, Mar 26, 2015 at 3:13 PM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: > $ Closing spawn id(3). > at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 1431 > Expect::hard_close('Expect=GLOB(0xd552470)') called at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 1621 > Expect::DESTROY('Expect=GLOB(0xd552470)') called at tester-b line 0 > eval {...} called at tester-b line 0 > spawn id(3) closed. > Pid 32508 of spawn id(3) terminated, Status: 0xFF00 Hi Andy, Sorry I don't have the time (or expertise) to go through your error messages - it's been ages since I've used expect and was mostly a novice when I was using it. Here is a snippet that I dredged up and verified that it ssh'ed. Please forgive the rough spots of the following code - it is many years old and I'm only posting it here as evidence that ssh'ing can be done. :) #!/usr/bin/perl use strict; use warnings; use Expect; my $debug = 0; my $TIMEOUT = 5; my $command = '/usr/bin/ssh user@host'; my $exp = Expect->spawn($command) or die "Cannot spawn $command: $!\n"; wait_for_and_send('Password:', "supersecretpassword\n", $exp); # I use the % sign in my prompt. You can change it to a $. wait_for_and_send('%', "date\n", $exp); sub wait_for_and_send { my $wait_for = shift; my $send = shift; my $exp = shift; if (&wait($wait_for, $exp)) { print "\nsending '$send'\n" if ($debug); $exp->send($send); return 1; } else { print "Did not wait.\n"; return undef; } } sub wait { my $prompt = shift; my $exp = shift; if ($exp->expect($TIMEOUT, $prompt)) { print "\nfound '$prompt'\n" if ($debug); return 1; } else { $exp->hard_close(); print STDERR "Timed out looking for prompt: '$prompt'\n"; return undef; } } -m |