我想实现下面的效果
ssh [email protected] (密码 admin) 登录后,运行 ls ,然后输入 exit 退出 最后把 ssh 的整个输出取出来
#!/usr/bin/expect -f
set timeout 10
spawn ssh [email protected]
expect {
"*yes/no" {
send "yes\n";
exp_continue
}
"*password:" {
send "admin\n"
}
"# " {
puts $expect_out(buffer)
send "exit\n"
expect eof
}
}
但是上面的代码好像有点问题,没法实现我想要的效果,请问这个应该怎么写?