From: Roland G. <rgi...@cp...> - 2008-09-23 14:18:58
|
Hi Ivo, I am trying to discourage the use of Expect for automating password entry for ssh because it's bad practice. Using the public key authentication in ssh is the right way to do it. In most cases you won't need Expect at all, just use qx(ssh host cmd) or open("-|", "ssh host cmd"). To answer some of your questions: commands within one expect() statement are parallel, a match of a regexp triggers the associated subroutine. For the new calling style with callbacks '-re' is the default, so you can leave it off, for the old-style expect() '-ex'act matching is the default, so you have to specify '-re' there to use regexp matches. Hope this helps, Roland ivo welch wrote: > Dear Roland: > > Thanks a lot for taking care of this module. It seems incredibly > useful, so I am now trying to learn it. Alas, not easy to figure out. > > One of the most common uses of Expect is probably use of "ssh" under > linux with a password that sits in my program. So, I am trying to > figure out from the docs what the recommended way to do this is. > Therefore, I think this could be a good candidate for an example. It is > probably obvious to the initiated, but not so to those of us that don't > even know the TCL Expect command. > > The logic of executing ssh would seem to suggest that I need to look > for: > > "Are you sure you want to continue connecting (yes/no)?" > to which I would answer "yes". This prompt may or may > not appear. > > "Password: " > to which I would give my password. This may or may not > appear the first time. > > "Password: " > a second time, which would lead me to die the program (I had the wrong > password). > > EOF > which should make me return happily. > > > It is not at all obvious to me how I would write a function > run_sshcommand( $remotecommand, $remotepassword ) > that automates this. From the docs, it is not easy to see if multiple > arguments to expect are sequential, or alternatives. Also, some > statements suggest I need "-re", other examples seem to suggest that I > can use qr//; > > Any help would be appreciated. > > Regards, > > /iaw > > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |