On Mon, 2010-01-04 at 02:38 +0100, Jeremiah Foster wrote:
> On Jan 4, 2010, at 24:15, Alvaro Mantilla Gimenez wrote:
> 
> > Hello,
> > 
> >  I know this is a Perl question but is not more easier to log in with
> > ssh public key method and execute the commands inside the foreach and
> > don't do all the username/password code?
> 
> Sometimes - like when you have a cluster of machines - it is easier and 
> faster to write a command once and have it execute on all the machines. 
> Expect is really good for this since you can just feed it a list of machines 
> and commands and expect just goes and does its thing.

Sorry...probably my bad English wasn't clear enough:

1.- You need one valid ssh account on each server (even if it is a
cluster of servers).
2.- SSH let's you execute remote commands on that servers.
3.- The perl script executes commands on that servers
4.- Expect do his part of the job with the outputs of the commands
executed.

So, you can share your public ssh key in each target server to log in
directly with the valid ssh account without a password (and save
yourself about the first part of the perl/expect code about the
authentication part using a much easier method to log in) and get a
valid procedure to execute the commands.

I agree with you that it is much easier to define the list of servers
with a var or maybe open a file...or whaterever...with that information.
Then the "foreach" just need to read that and execute the commands but
free of the too much code doing the authentication and validation
responses about the username/password.

Don't you think?

 Regards,

   Alvaro

> >> 
> >> foreach ("10.10.10.1", "10.10.10.2") {
> >> print "Spawning to the $_\n";
> >> $exp->spawn("ssh -l username $_") or warn "unable to spawn: $!";
> 
> Don't you think it is much clearer to add a name to the default var? Like 
> this:
> 
> my @servers = qw/ 10.10.10.1 10.10.10.2 /;
> foreach my $server (@servers)
>       print "Spawning to $server\n";
>       $exp->spawn("ssh -l username $_") or warn "unable to spawn: $!";
> 
> >> 
> >> 
> >> #This part checks for the password prompt, if it doesn't get the password
> >> prompt the errors are displayed.
> >> unless($exp->expect(10, '-re','.*password:\s*')){
> 
> I haven't tested all your code, but expect is notoriously difficult to use. 
> Matching the prompt and such exactly is a pain. Expect itself offers a little 
> bit easier debugging output sometimes too.
> 
> Jeremiah


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to