[Explain pertinence--typical situations (firewalling), ...]
[© Phaseit 2009]
[Explain configurations.]
This particular model first ssh-s to a machine which demands a passphrase, then ssh-s to a third host, where, after a demand for a password, it requests a directory listing of the home directory: ls.
package require Expect set command ls set timeout -1 # That's silly; next time just "spawn ssh ..." directly. spawn $env(SHELL) match_max 100000 log_user 0 expect $prompt0 send -- "ssh [email protected]$host1\r" expect -glob "Enter passphrase for key '*': " send -- $passphrase1\r expect $prompt1 send -- "ssh [email protected]$host2 $command\r" expect "assword: " send -- $password2\r expect $prompt1 set presult $expect_out(buffer) send -- exit\r expect $prompt0 send -- exit\r expect eof # $presult deserves a little prettification--stripping off the last line, ... puts $presult