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\r";exp_continue}
"password:" {send "$pwd\r"}
}
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\r";exp_continue}
"password:" {send "$pwd\r"}
}
interact  # 保持在远程终端
 

 

posted @ 2018-12-31 16:29  Ray_chen  阅读(312)  评论(0编辑  收藏  举报