ログインを自動化し、リモートマシンでコマンドを実行するために使用したphpスクリプトがあります。これは私のphpコードのようです、
<?php
ini_set("expect.loguser", "Off");
$stream = fopen("expect://ssh root@10.3.2.0", "r");
$cases = array (
array (0 => "*(yes/no)?", 1 => YESNO),
array (0 => "*d: ", 1 => PASSWORD),
array (0 => "*$ ", 1 => SHELL, EXP_EXACT)
);
switch (expect_expectl ($stream, $cases)) {
case YESNO:
fwrite ($stream, "yes\n");
break;
case PASSWORD:
fwrite ($stream, "myrootpassword\n");
break;
case SHELL:
fwrite ($stream, "top -n 1\n");
break;
default:
die ("Error was occurred while connecting to the remote host!\n");
}
while ($line = fgets($stream)) {
print $line;
}
fclose ($stream);
?>
また、PHPのexpectモジュールもインストールしたことを知っています。
Ubuntuマシンにも期待をインストールしました。
しかし、これがスクリプトが機能しない理由がわかりません。http://www.php.net/manual/en/book.expect.phpおよびhttp://php.net/manual/en/expect.examples-usage.phpに従って、php スクリプト ファイルを作成しました。私はPHPの初心者なので、PHPで動作するためにどのような変更を加える必要があるか教えてください。
ありがとう。