From: Noah <ad...@en...> - 2008-06-10 18:25:47
|
Hi, sometimes the RSA fingerprint is not in ~/.ssh/known_hosts so the prompt could be different. what would be the best way to handle the differences. there is one more prompt to handle, defined as $prompt2, when the IP or hostname does not appear in ~/.ssh/known_hosts. How would you handle the condition and then move back to accepting $prompt1? $prompt1 = ".*password:"; $prompt2 = "^[^?]+?\s"; my $patidx = $exp->expect($timeout, [$prompt]); Cheers, Noah |
From: Austin S. <te...@of...> - 2008-06-10 18:34:12
|
On Tue, Jun 10, 2008 at 11:25:19AM -0700, Noah wrote: > Hi, > > sometimes the RSA fingerprint is not in ~/.ssh/known_hosts so the prompt > could be different. > > what would be the best way to handle the differences. there is one more > prompt to handle, defined as $prompt2, when the IP or hostname does not > appear in ~/.ssh/known_hosts. How would you handle the condition and > then move back to accepting $prompt1? > > > > $prompt1 = ".*password:"; > $prompt2 = "^[^?]+?\s"; > my $patidx = $exp->expect($timeout, [$prompt]); > Expect both prompts at once. Run until $prompt1 is matched. You can do this one of two ways: use the simple interface and wrap it in a while loop, or you can use the "Tcl like" interface and use exp_continue. See the expect example in the synopsis section of the docs. Austin |
From: Sorrell, A. <Al_...@tr...> - 2008-06-10 18:49:25
|
> -----Original Message----- > From: exp...@li... [mailto:expectperl- > dis...@li...] On Behalf Of Austin Schutz > Sent: Tuesday, June 10, 2008 2:34 PM > To: Noah > Cc: exp...@li... > Subject: Re: [Expectperl-discuss] conditional prompt? > > On Tue, Jun 10, 2008 at 11:25:19AM -0700, Noah wrote: > > Hi, > > > > sometimes the RSA fingerprint is not in ~/.ssh/known_hosts so the prompt > > could be different. > > > > what would be the best way to handle the differences. there is one more > > prompt to handle, defined as $prompt2, when the IP or hostname does not > > appear in ~/.ssh/known_hosts. How would you handle the condition and > > then move back to accepting $prompt1? > > > > > > > > $prompt1 = ".*password:"; > > $prompt2 = "^[^?]+?\s"; > > my $patidx = $exp->expect($timeout, [$prompt]); > > > > Expect both prompts at once. Run until $prompt1 is matched. > You can do this one of two ways: use the simple interface > and wrap it in a while loop, or you can use the "Tcl like" interface and > use exp_continue. See the expect example in the synopsis section of the > docs. > > Austin > Possibly something like this: # # Might get the warning about "Are you sure you want to continue connecting (yes/no)?" # $exp->expect(2, ['yes/no', sub { my $fh = shift; $fh->send("yes\n");$stat=0;}]); $exp->expect($timeout, ['assword:', sub { my $fh = shift; $fh->send("$auth_pass\n"); $stat=0;}], [timeout => sub {print STDERR " *** cisco_login:Timed out waiting for (auth) 'assword:'\n"; $stat=1;}] ); print "After waiting for SSH 'assword:', stat=$stat\n" if($DEBUG>1); return($stat,'') if($stat); The contents of this e-mail and any attachments are intended solely for the use of the named addressee(s) and may contain confidential and/or privileged information. Any unauthorized use, copying, disclosure, or distribution of the contents of this e-mail is strictly prohibited by the sender and may be unlawful. If you are not the intended recipient, please notify the sender immediately and delete this e-mail. |
From: Noah <ad...@en...> - 2008-06-10 20:55:30
|
perfect - thanks! Sorrell, Al wrote: > > >> -----Original Message----- >> From: exp...@li... > [mailto:expectperl- >> dis...@li...] On Behalf Of Austin Schutz >> Sent: Tuesday, June 10, 2008 2:34 PM >> To: Noah >> Cc: exp...@li... >> Subject: Re: [Expectperl-discuss] conditional prompt? >> >> On Tue, Jun 10, 2008 at 11:25:19AM -0700, Noah wrote: >>> Hi, >>> >>> sometimes the RSA fingerprint is not in ~/.ssh/known_hosts so the > prompt >>> could be different. >>> >>> what would be the best way to handle the differences. there is one > more >>> prompt to handle, defined as $prompt2, when the IP or hostname does > not >>> appear in ~/.ssh/known_hosts. How would you handle the condition > and >>> then move back to accepting $prompt1? >>> >>> >>> >>> $prompt1 = ".*password:"; >>> $prompt2 = "^[^?]+?\s"; >>> my $patidx = $exp->expect($timeout, [$prompt]); >>> >> Expect both prompts at once. Run until $prompt1 is matched. >> You can do this one of two ways: use the simple interface >> and wrap it in a while loop, or you can use the "Tcl like" interface > and >> use exp_continue. See the expect example in the synopsis section of > the >> docs. >> >> Austin >> > Possibly something like this: > > # > # Might get the warning about "Are you sure you want to continue > connecting (yes/no)?" > # > $exp->expect(2, > ['yes/no', > sub { my $fh = shift; $fh->send("yes\n");$stat=0;}]); > $exp->expect($timeout, > ['assword:', > sub { my $fh = shift; $fh->send("$auth_pass\n"); > $stat=0;}], > [timeout => > sub {print STDERR " *** cisco_login:Timed out waiting for > (auth) 'assword:'\n"; > $stat=1;}] > ); > print "After waiting for SSH 'assword:', stat=$stat\n" > if($DEBUG>1); > return($stat,'') if($stat); > > > The contents of this e-mail and any attachments are intended solely for the use of the named addressee(s) and may contain confidential and/or privileged information. Any unauthorized use, copying, disclosure, or distribution of the contents of this e-mail is strictly prohibited by the sender and may be unlawful. If you are not the intended recipient, please notify the sender immediately and delete this e-mail. |