Linux expect 期望在提示中出现连字符

Linux expect expecting a hyphen in the prompt

因此,我有一个 expect 脚本,该脚本会发送到 HPE 虚拟连接模块以 运行 显示所有命令。但是,当我在"Expecting"提示符“->”时,我得到一个错误:

bad flag "-> ": must be -glob, -regexp, -exact, -notransfer, -nocase, -i, -indices, -iread, -timestamp, -timeout, -nobrace, or --
while executing
 "expect "-> ""
(file "./expect_vc_showall.ziUzpF" line 10)

这是我的代码:

 #!/usr/bin/expect -f
 set timeout 60
 set ip_hostname [lindex $argv 0];
 #log_user 0
 spawn ssh Administrator@$ip_hostname
 expect {
     "*yes/no*" { send "yes\r"; exp_continue }
     "*assword:" { send "password123\r" }
  }
 expect "-> "
 send "show all\r"
 #log_user 1
 expect "-> "
 send "exit\r"

我曾尝试使用 expect -- "-> ",但这只会让我进入提示,然后就死掉了。

提示如下所示:

 Last login: Thu Jul 27 17:09:28 2017 from 172.16.100.78
 ------------------------------------------------------------------------------- 
 HP Virtual Connect Management CLI v4.41
 Build: 4.41-6 (r315367) Mar  5 2015 13:59:31
 (C) Copyright 2006-2015 Hewlett-Packard Development Company, L.P.
 All Rights Reserved
 -------------------------------------------------------------------------------


 GETTING STARTED: 

 help           : Displays a list of available subcommands 
 exit           : Quits the command shell 
 <subcommand> ? : Displays a list of managed elements for a subcommand 
 <subcommand> <managed element> ? : Displays detailed help for a command 

 ->

如果我只是做一个期望“>”,它会在第一个子命令文本处死掉。

有什么想法可以让它发挥作用吗?

谢谢! 乔

你可以做到

expect -- "-> "

或使用不以连字符开头的 glob 模式(更加混乱)

expect {[-]> }

expect 的默认模式类型是 glob,并且有一个明确的标志:

expect -gl "-> "

但是,您的模式没有 glob 字符,因此您也可以使用 exact 标志:

expect -ex "-> "