TCL expects regex


I am trying to write one script that rises from one system to another through TCL / Expect. He works for me. I need a regular expression in which to expect "$" and expect "#" , so any system with any prompt in transit may be included.

#!/usr/bin/expect # Using ssh from expect log_user 0 spawn ssh test@192.168.2.24 expect "sword: " send "test\r" expect "$ " send "ssh beta\r" expect "# " send "uptime\r" expect "# " set igot $expect_out(buffer) puts $igot 
+8
regex tcl expect
source share
2 answers

Use this:

  expect -re {[$ #]} 
+13
source share

More general solution:

 set prompt "(%|#|\\\$) $" expect -re $prompt 

This corresponds to % , # and $ .
The second dollar sign guarantees compliance with the pattern only at the end of input.

+8
source share

All Articles