in reply to expect using ssh
Hope it helps. If you have any questions or problems, let me know and I'd be glad to help.#!/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'); }
|
|---|