expect无交互操作

#!/usr/bin/expect

set ip '192.168.4.5'
set pwd '123456'
set timeout 30

spawn ssh root@$ip 
expect {
"yes/no" {send "yes
";exp_continue}
"password:" {send "$pwd
"}
}
interact  # 保持在远程终端

#!/usr/bin/expect

set ip [lindex $argv 0]   # 第一个位置参数
set user [lindex $argv 1] 
set pwd [lindex $argv 1]
set timeout 30

spawn ssh $user@$ip 
expect {
"yes/no" {send "yes
";exp_continue}
"password:" {send "$pwd
"}
}
interact  # 保持在远程终端
 
原文地址:https://www.cnblogs.com/ray-mmss/p/10202375.html