Reputation: 57
So, I have an expect script that goes out to an HPE virtual connect module to run a show all command. However, when I am "Expecting" the prompt "->", Im getting an error:
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)
Here is my code:
#!/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"
I have tried to use expect -- "-> " but that just brings me to the prompt and then dies.
Here is what the prompt looks like:
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
->
If I just do a expect "> ", it dies at the first subcommand text.
Any ideas how to get this to work?
Thanks! Joe
Upvotes: 1
Views: 628
Reputation: 12255
The default pattern type for expect is a glob, and there is an explicit flag for that:
expect -gl "-> "
However, your pattern has no glob characters, so you could also use the exact flag:
expect -ex "-> "
Upvotes: 2
Reputation: 247210
You can do
expect -- "-> "
or use a glob pattern that doesn't start with a hyphen (much messier)
expect {[-]> }
Upvotes: 0