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. >> >> 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/