Reputation: 6288
So I need an output of the remote process on my stdout, but I need also to be able to "listen" to it, and send the command after matching my keyword.
I need something like this (I know this code is not correct, it's only purpose is illustration of what I need)
#!/usr/bin/expect
log_user 0
spawn ssh -o PubkeyAuthentication=no [lindex $argv 0] -n [lindex $argv 1]
expect "Password:" {send "mypassword\r"}
interact
expect "mykeyword" {send "\003\177\015"}
Upvotes: 3
Views: 10505
Reputation: 137797
If I remember right, you do this:
#!/usr/bin/expect
log_user 0
spawn ssh -o PubkeyAuthentication=no [lindex $argv 0] -n [lindex $argv 1]
expect "Password:" {send "mypassword\r"}
interact {
"mykeyword" {
send "\003\177\015"
exp_continue
}
}
You pass the things to watch out for and actions to take as arguments to interact
(just like with expect
) and you tell the response script to exp_continue
at the end so that it keeps on interacting/expecting.
Upvotes: 7