[英]TCL expect regular expression
I am trying to write one script which climbs up from one system to another through TCL/Expect.我正在尝试编写一个脚本,该脚本通过 TCL/Expect 从一个系统爬升到另一个系统。 It is working for me.
它对我有用。 I need a regular expression in which expect "$ " and expect "# " is combined , so that any system with any prompt in the path can be included.
我需要一个正则表达式,其中组合了expect "$"和expect "#" ,以便可以包含路径中带有任何提示的任何系统。
#!/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
Use this:用这个:
expect -re {[$#] }
The keys to this are: add the -re
flag so that we can match an RE, and put the RE in {braces}
so that it doesn't get substituted.关键是:添加
-re
标志以便我们可以匹配 RE,并将 RE 放在{braces}
以便它不会被替换。
A more generic solution:更通用的解决方案:
set prompt "(%|#|\\\$) $"
expect -re $prompt
This one matches % , # and $ .这个匹配% 、 #和$ 。
The second dollar sign ensures matching the pattern only at the end of input.第二个美元符号确保仅在输入末尾匹配模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.