>>619のプログラム

#!/usr/bin/perl -w
use DBI;
use Expect;
$user = "foo";
$pass = "bar";
$db_name = "giko";
$table_name = "testdb";
$db = DBI->connect("DBI:mysql:$db_name:localhost", $user, $pass);
$sth = $db->prepare("select * from $table_name");
$sth->execute;
while (@a = $sth->fetchrow_array) {
for ($i = '2'; $i < '6'; $i++) {
if ($a[$i]) {
$exp[$i]=Expect->spawn("ssh -v -o ConnectTimeout=$timeout $user\@$a[$i]\n");
$exp[$i]->expect(300,
[ qr/\(yes\/no\)/ => sub { my $self = shift; $self->send("yes\n"); exp_continue; }],
[ qr/password:/i => sub { my $self = shift; $self->send("$pass\n"); exp_continue; }],
'$'
);
$exp[$i]->send("/sbin/ifconfig -a\n");
$exp[$i]->expect(300,'$');
$exp[$i]->send("exit\n");
$exp[$i]->close();
}
}
}
$sth = $db->disconnect();