> brickwalls19 wrote:
> > I'm working on a small Expect/tcl script for logging into a switch. I
> > can't figure out how to do the following that's between the question
> > marks.
> > expect -re "(enable\\) \*$)|(> *\ *$)|(# *\ *$)"
> > ????
> > what i want to do next --> if the prompt ends in either '(enable)',
> > '>', or '#', assign it to the variable "login".
> > ????
> > switch -- $login {
> > "> *\ *$" {
> > send "en\r"
> > expect "ssword"
> > send "$password\r"
> > send "config t\r"
> > }
> > "enable\\) \*$" {
> > send "\n\r"
> > }
> > "# *\ *$" {
> > send "config t\r"
> > }
> > default {
> > send " \n"
> > }
> > }
> > Also if anyone can see a simpler way this can be done I'd appreciate
> > it. Definitely trying to use Expect/tcl to make my work assignments
> > easier and bearable. Also a learning opportunity.
> the expect_out array will contain the full match and submatches
> so
> set login $expect_out(1,string)
> will do what you ask, but you can alos skip the double step of
> matching a, b or c and the doing a switch on a, b or c
> with the following
> expect {
> -re "> *\ *$" {
> send "en\r"
> expect "ssword"
> send "$password\r"
> send "config t\r"
> }
> -re "enable\\) \*$" {
> send "\n\r"
> }
> -re "# *\ *$" {
> send "config t\r"
> }
> timeout {
> send " \n"
> }
> }
> Bruce
Thanks Bruce. Your alternative works for me and straight forward.