0

我已经检查了许多不同的方法来解决这个问题,它可能是特定于环境的。我在 Ruby 中创建一个脚本来远程登录到远程服务器,登录,输入 shell 类型(登录后的提示符,前面没有“提示符”),然后在下一个提示符处输入用户 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 回答