pcdj has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: expect using ssh
by joe++ (Friar) on Oct 17, 2002 at 21:38 UTC
    Please, please *please* don't store (login-) passwords in scripts!

    With SSH you have excellent alternatives, a much more secure option being to use host keys. If you generate a key locally (sshkeygen) without password, and exchange the pubkey, you can connect *as this user* without password and without hassle.

    Of course, the security is limited to the level of trust you have for the specified account, but that is another story and pretty much under your control.

    I have at work a simple step-by-step description, could add that tomorrow if you like...

    Update: added links about setting up SSH the proper way. See followup to your duplicated post: Re: Re: Connecting to machines.

    --
    Cheers, Joe

Re: expect using ssh
by sschneid (Deacon) on Oct 17, 2002 at 21:17 UTC
    This is untested, but it should do what you're looking for.
    #!/usr/local/bin/perl -w use Expect; use strict; my @hosts = ('192.168.0.2', '192.168.0.3', '192.168.0.4'); my $password = 'p4ssw0rd'; foreach (@hosts) { my $exp = Expect->spawn('ssh $_ cmd_to_run; echo done') or die "Could not connect to $_: $!"; if ($exp->expect(undef, 'assword')) { $exp->send("$password\cM"); } $exp->expect('done'); }
    Hope it helps. If you have any questions or problems, let me know and I'd be glad to help.
    scott.