68user's page 掲示板

Prev< No. 1340> Next  [最新発言に戻る] [過去ログ一覧]
No. 1340 # rosegarden 2000/11/10 (金) 02:48:35
私の場合、次のような感じのスクリプトで動きます。
一応、ログインしてコマンド実行程度なら、大丈夫のようです。
環境は perl 5.00503 + Expect-1.08 + FreeBSD 4.2-BETA です。

#!/usr/bin/perl

use Expect;

my $user = 'rose';
my $password = 'password';
my $prompt = 'host\{rose\}\d+\s';

my @cmdlist = (
        'ls -alF',
        'ps -auxw',
        'exit',
        );

my $telnet = Expect->spawn("telnet localhost");

$telnet->expect(30,"login: ") || die "NO login prompt";
print $telnet "$user\r";

$telnet->expect(30,"assword:") || die "NO password prompt";
print $telnet "$password\r";

my $match = $telnet->expect( 30,
        "closed by foreign host",
        "-re", $prompt
        );

die "refused by server\n" if $match == 1;
die "NO shell prompt, ".$telnet->exp_error()."\n" unless $match;

foreach $cmd ( @cmdlist ) {
        print $telnet "$cmd\r";

        my $match = $telnet->expect(
                30,
                "closed by foreign host",
                "-re", $prompt
                );
        last if $match == 1;
        die "NO prompt after command\n" if $telnet->exp_error();
}

$telnet->hard_close();
exit;

Prev< No. 1340> Next  [最新発言に戻る] [過去ログ一覧]