0

これを修正するさまざまな方法をチェックアウトしましたが、環境に固有のものである可能性があります。Rubyでスクリプトを作成して、リモートサーバーにtelnetでログインし、シェルタイプを入力して(ログイン後のプロンプトで、前に「プロンプト」がありません)、次のプロンプトでユーザーIDを入力します。現在、ユーザーとパスを介してログインしていますが、用語の部分でフリーズしています。私は正規表現、文字列、スリープを使用してから puts("xterm" を使用しようとしましたが、このプロンプトを通過することはできません。ハングアップしているコードのスニペットとそれに沿った出力を次に示します。

$telnet = Net::Telnet::new("Host" => 'hostname',
                       "Output_log" => 'output.txt',
                       "Dump_log" => 'Dump.txt',
                       "Binmode" => false,
                       "Timeout" => false,
                       "Prompt" => /.* $ $/) { |c| print c }
$telnet.login("user", "pass") { |c| print c }
$telnet.waitfor("TERM = (xterm) ")
$telnet.puts("xterm") { |c| print c }
$telnet.waitfor(Match => /Enter\s*$/) { |c| print c }
$telnet.puts("userid")

出力は次のとおりです。

HP-UX ds107492 B.11.11 U 9000/800 (tm)

login: user
Password: 
Please wait...checking for disk quotas
. i

.[ci

.*s1^i

See /etc/copyright for copyright notices
You have mail.
'You have mail.'
TERM = (xterm) 
4

1 に答える 1

1
$s.waitfor("Match" => /TERM\s*/){ |c| print c }
$s.print("xterm\n"){ |c| print c }

答えのようです、それは私がプロンプトを通り過ぎることを可能にしました。この正規表現と私が試した他のすべての正規表現の違いはまだわかりません:/

于 2014-12-16T11:06:52.467 に答える