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 $account@phaseit.net expect {assword: } send $password\r expect "\\$ " send "grep $pattern $filename\r" expect -re "\[^\n]*\n(.*)\n.*\\$ " puts $expect_out(1,string) send exit\r expect eof ---- [[Show how to put it in a proc.]] ---- [[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 |% !!!!!!