#!/usr/bin/expect
set timeout 10
spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2]
expect {
"(yes/no)?"
{send "yes
";exp_continue}
"password:"
{send “<password>
"}
}
expect “*<服务器名>*" {send "ssh [lindex $argv 3]@[lindex $argv 4]
"}
expect "*password:" {send "[lindex $argv 5]
"}
#expect eof
interact
在mac上使用iTerm连接服务器,不能保存密码,通过expect脚本来实现自动密码输入
一般公司内部只能通过跳板机登录,通过上面的脚本可以实现连续登录 ,具体的iTerm配置参考网上其它教程
通过expect脚本还可以实现更复杂的自动化运维
参考: