8


I am trying to write one script which climbs up from one system to another through 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.

#!/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
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
Harikrishnan R
  • 1,444
  • 4
  • 16
  • 27

2 Answers2

13

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.

miken32
  • 42,008
  • 16
  • 111
  • 154
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
8

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.

asdone
  • 191
  • 2
  • 8