[英]expect_out(buffer) not being assigned
I need some help with a expect script I'm writing to get information from a router I can't reach directly. 我在编写期望脚本时需要一些帮助,以从无法直接到达的路由器获取信息。 This is my code: 这是我的代码:
expout=$(
expect << EOD
log_user 0
set timeout 20
spawn ssh router1
expect "router1#" { send "ssh -l foo 0.0.0.0\r" }
expect "Password:" { send "*********\r" }
expect "router2#" { send "show ip interface br\r \r" }
set output $expect_out(buffer)
expect "router2#" { send "exit\r" }
expect "router1#" { send "exit\r" }
puts $output
expect eof
EOD
)
I'm expecting to save that output to a bash variable for further manipulation. 我期望将输出保存到bash变量中,以进行进一步操作。 If I enable exp_internal 1
in the script it does assign what I want to expect_out(buffer) . 如果我在脚本中启用exp_internal 1
,则它确实分配了我想要的Expect_out(buffer) 。 Can you tell me if I'm doing something wrong? 你能告诉我我做错了什么吗?
Thanks! 谢谢!
Because the heredoc is unquoted, the shell is expanding $expect_out
to the empty string before expect launches. 因为heredoc是未引用的,所以shell会在期望启动之前将$expect_out
扩展$expect_out
空字符串。 Then expect only sees set output (buffer)
然后期望只看到set output (buffer)
Quote the heredoc: 引用heredoc:
expect=$(
expect << 'EOD'
# ........^...^
... expect code
EOD
)
See https://www.gnu.org/software/bash/manual/bashref.html#Here-Documents 参见https://www.gnu.org/software/bash/manual/bashref.html#Here-Documents
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.