Greetings.
I have a problem with expect of tcl, when enter a server.
My script is thus:
package require Expect
set pid [spawn telnet 10.10.10.17]
set id $spawn_id
expect -i $id timeout {
puts "timeout in user login"
} eof {
puts "spawn failed with eof on login"
} -re "login:.*" {
exp_send -i $id -- "admin\r"
}
expect -i $id timeout {
puts "timeout in user password"
} eof {
puts "spawn failed with eof on password"
} -re "Password:.*" {
exp_send -i $id -- "_adm1n_\r"
}
expect -i $id timeout {
puts "timeout in user local"
} eof {
puts "spawn failed with eof on local"
} -re "\[local\]SE100#" {
exp_send -i $id -- "context switched\r"
}
exp_close -i $id
#!/usr/bin/expect
package require Expect
set pid [spawn telnet 10.10.10.17]
set id $spawn_id
expect -i $id timeout {
puts "timeout in user login"
} eof {
puts "spawn failed with eof on login"
} -re "login:.*" {
exp_send -i $id -- "admin\r"
}
expect -i $id timeout {
puts "timeout in user password"
} eof {
puts "spawn failed with eof on password"
} -re "Password:.*" {
exp_send -i $id -- "_adm1n_\r"
}
expect -i $id timeout {
puts "timeout in user local"
} eof {
puts "spawn failed with eof on local"
} -re "\[local\]SE100#" {
exp_send -i $id -- "context switched\r"
}
exp_close -i $idAnd I cannot capture with expect this chain "[local]SE100#"
I will be thankful for some aid
--------
Douglas Aparicio Bermudez.
Hi Aparicio,
Are you suer that you have to expect regular expression instead of string directly?
Are those [ ] # chars in the string or they are placeholders...
I think you should do:
puts "spawn failed with eof on local"
} "\[local\]SE100#" {
exp_send -i $id -- "context switched\r"
instead.
Regards
Jorge
You have to remember that angle brackets have special meaning to both TCL and the expect pattern matcher.
So "\[" means TCL treats it as a literal pattern.
But the pattern matcher treats it a list of characters l,o,c,a,l
What you actually want is:
\\\[local\\\]SE100#
to match a literal "[local]"
This is covered in 'Exploring Expect'