Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expect prompt question 2

Status
Not open for further replies.

grepper

Technical User
Jun 4, 2003
49
0
0
US
I have a Expect script that works for my prompts but we are thinking about sharing it w/ other UNIX groups within the company. Problem is their prompts are most likely different. So what I need to do is something like this:

expect -exact "login:"
send -- "$user\r" #user name
expect -exact "$user's Password: "
send -- "$pass\r" #user password
expect "What ever their prompt might be"

I think you can do a set prompt "various prompts" and just expect $prompts, or something like that. Any help would be great.

Grepper

 
Sure..use a regular expression..don't attempt to match exactly.

Code:
    expect -re ".*@.*" {do_action}
 
I use the following (we have 42 servers):

# Basic user prompt: [xxxx]$
set prompta "\\\[.*\\\]$"
# Root user prompt: :xxxx#
set promptb ":.*# "
# Other user prompts: xxxx/> or xxxx$ or [MCS]xxxx> or xxxx:yyyy>
set promptc ".*\\\/>|.*\\\$|\\\[MCS\\\].*>|.*:.*>"

...

expect -re $prompta {
...
} -re $promptb {
...
}


Regards,
-Niel
 
Thanks, I ended up w/ something like this. Works pretty good.

set prompt "(%|#|]|:|>|\\$) $";
catch {set prompt $env(EXPECT_PROMPT)}

The catch line looks for the expect_prompt varible, if it can't find it, Expect will use the first set prompt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top