From: Roland G. <ro...@gi...> - 2017-03-27 15:02:32
|
Right, I released the posting on hold without noticing that it had been resent. 😊 Sorry for the confusion... Roland -----Original Message----- From: Bob McGowan [mailto:ram...@gm...] Sent: Sonntag, 26. März 2017 04:24 To: mike nicholas <mik...@gm...> Cc: exp...@li... Subject: Re: [Expectperl-discuss] Help with legacy expect code No, I did not. I guess I misunderstood the email from the moderator regarding my attempt to post while not a member of the list. I thought the first attempt would be rejected, so I joined the list and sent the email as a member. I assume the first one actually was released, hence the double post. My apologies for that. By the way, I did answer your first two responses, and thought I had included the list, but that did not show up in my mailbox (I think I have things set so it should have). Please let me know if you get this, either way. Thanks, Bob On 03/25/2017 12:49 PM, mike nicholas wrote: > Hello again, Bob, > > Did you truly intend to re-send the same email from yesterday? Were > you able to test those previous suggestions? > > Thanks kindly! > > On Mar 25, 2017 8:50 AM, "McGowan Jr, Bob" <bob...@sa...> wrote: > >> Hello List, >> >> I'm supporting legacy code that uses Expect, but I'm no expert at >> 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. >> >> Also, I have not signed up to the list, since I hopefully will have >> no future needs in this arena. So please reply all. >> >> Before the section that does the Expect processing, below, 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, $password); >> 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 is 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... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> > > > > ---------------------------------------------------------------------- > -------- 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... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > ------------------------------------------------------------------------------ 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... https://lists.sourceforge.net/lists/listinfo/expectperl-discuss |