|
From: Bob M. <ram...@gm...> - 2017-03-25 03:53:05
|
Hi Mike,
No need for such formality, I generally respond well to Bob :)
I like your suggestions, particularly the second. In hindsight (which
is almost always 20/20, or better), I wonder why I didn't think of it.
It is so obvious. :(
I will come back once I've tried it, and let you know how it worked out.
Thanks,
Bob
On 03/24/2017 04:09 PM, mike nicholas wrote:
> Or perhaps, send a carriage return from the enclosing expect call,
> after it returns back, to get another prompt back to match for and
> continue execution ?
>
> On Fri, Mar 24, 2017 at 6:04 PM, mike nicholas
> <xmi...@gm... <mailto:xmi...@gm...>> wrote:
>
> Hi Mr. McGowan,
>
> Just a shot in the dark, but:
>
> # instead of this:
> ##################
>
> $ssh->expect(0, '-re', "$pat");
> $ssh->log_file(\&logMethod) if $logging;
> return $ssh->error();
> };
>
> # You may want to try:
> ######################
>
> $ssh->expect(5,
> [ '-re', $pat => sub { $ssh->log_file(\&logMethod) if
> $logging;
> return $ssh->error();
> }],
>
> ['-re', $contains_stuff => sub { break;
> }],
> );
>
> Maybe try setting $contains_stuff to something you would expect on
> success i.e. no pw being echo'd back ?
>
> On Fri, Mar 24, 2017 at 4:52 PM, Bob McGowan <ram...@gm...
> <mailto:ram...@gm...>> wrote:
>
> Hello List,
>
> I'm supporting legacy code that uses Expect, but I'm no expert
> with this tool. Nor can I figure out a way to pose the
> question to the archive server to search for anything helpful,
> so here I am, hoping for an answer. :)
>
> Before the section that does the Expect processing, there is a
> sub defined as follows:
>
> $passHandler = sub {
> my ($ssh, $logging, $password) = @_;
> $ssh->log_file(undef);
> $ssh->stty(qw(-echo));
> print $ssh "$password\r";
> $ssh->stty(qw(echo));
> $pat = quotemeta($password);
>
> $ssh->expect(0, '-re', "$pat");
>
> $ssh->log_file(\&logMethod) if $logging;
> return $ssh->error();
> };
>
> There are a number of other patterns to look for besides the
> two prompts listed below, each with appropriate logic
> contained in other 'sub' definitions. My problem is with the
> second prompt. Also, I'm not being pedantic here about format
> or syntax, this is not intended to run (currently).
>
> $expectObj->expect($timeout,
> '-re', $prompt1, sub {
> $failed = $passHandler->($ssh, $logging,
> $password);
> if ($failed) {
> return "something";
> } else {
> return exp_continue_timeout();
> }
> },
> '-re', $prompt2, sub {
> $output = $ssh->exp_before();
> if ($secondPass) {
> $failed = $passHandler->($ssh, $logging,
> $secondPass);
> if ($failed) {
> return 'something';
> } else {
> return exp_continue_timeout();
> }
> } else {
> return # an error
> }
> },
> ...
> );
>
> I have run the original code with debugging on.
>
> Processing $prompt1 happens before processing for $prompt2.
> $prompt1 is the login prompt passed through by 'ssh'.
>
> Handling the ssh login step works fine.
>
> Processing the second prompt looks for a string like 'Enter
> secondary password: ' which is detected correctly and
> processing goes into the passHandler, where the password is sent.
>
> The function then does the 'expect' on the password "pattern",
> which is there to be sure we don't get any echo'ed password
> passed through.
>
> But in the failing case, there is no password echoed, and the
> next set of returned strings contains stuff that doesn't
> match, within the passHandler. So it times out.
>
> Upon returning to the enclosing 'expect' call, expect
> immediately begins 'waiting' for new data. The strings that
> were picked up in passHandler are not looked at, and
> unfortunately they have the next string being 'waited' for, so
> the whole thing times out and processing fails.
>
> I'm happy to try to make something that actually runs, if that
> is needed, but that will take a bit more time and I hope this
> is enough to point someone in the right direction.
>
> Many thanks,
>
> Bob
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Expectperl-discuss mailing list
> Exp...@li...
> <mailto:Exp...@li...>
> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss
> <https://lists.sourceforge.net/lists/listinfo/expectperl-discuss>
>
>
>
|