所以,我有一个期望脚本,可以通过HPE虚拟连接模块运行show all命令。然而,当我和他一起期待"提示" - >",我收到错误:
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
->
如果我只是期待&#34;&gt; &#34;,它在第一个子命令文本处死掉。
任何想法如何让这个工作?
谢谢! 乔
答案 0 :(得分:2)
expect的默认模式类型是glob,并且有一个显式标志:
expect -gl "-> "
但是,您的模式没有glob字符,因此您也可以使用确切的标志:
expect -ex "-> "
答案 1 :(得分:0)
你可以做到
expect -- "-> "
或使用不以连字符开头的圆形图案(更加混乱)
expect {[-]> }