Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

TCL(Tool Command Language) Scripting

subpatterns in Expect regexp and assigning to a variable


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
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.

On May 22, 2:07 pm, Bruce Hartweg <doNOT@nowhere.com> wrote:

Thanks Bruce. Your alternative works for me and straight forward.

Jeff

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc