一个通用的想法可以如下所示。
spawnssh 会话send expect例子:
spawn ssh $user@$domain
expect "password" { send "$pwd\r"}
expect "#"; # This '#' is nothing but the terminal prompt
send "$cmd\r"
expect "#"
puts $expect_out(buffer);  #Will print the output of the 'cmd' output now.
执行命令后等待的字可能因您的系统而异。它可以是#或$或>; :因此,请确保您提供的是正确的信息。或者,您可以为提示提供通用模式
set prompt "#|>|:|\\\$"; # We escaped the `$` symbol with backslash to match literal '$'
发送命令后使用时expect,可用作
expect -re $prompt; #Using regex to match the pattern`