There turns out not to be a single right answer. Here are several small essays on the question:


    package require Expect

    log_user 0

    spawn ssh [email protected]
    expect {assword: }
    send $password\r
    expect $prompt
    send "grep $pattern $filename\r"
    expect -re "\[^\n]*\n(.*)\n.*$prompt"
    puts $expect_out(1,string)
    send exit\r
    expect eof

[Show how to put it in a proc.]


[Show an RE-free version.]


[Show a more max_match-resistant version.]


[Introduce exception-handling.]


[Illustrate reliance on "How to access the result of a remote command in Expect"]


enter categories here