1、写脚本,放到/usr/local/bin
#!/usr/bin/expect set timeout 30 spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2] expect { "(yes/no)?" {send "yes ";exp_continue} "password:" {send "[lindex $argv 3] "} } interact
2、给权限:chmod +x logintest.exp
3、写命令文本:
logintest.exp 22 root 10.74.168.103 o7jSSB99PuDH