在/usr/local/bin目录下新建iterm2login.sh文件,内容如下
#!/usr/bin/expect
set timeout 30
spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2]
expect {
"(yes/no)?"
{send "yes\n";exp_continue}
"password:"
{send "[lindex $argv 3]\n"}
}
expect "~"
send "clear\n"
interact
授权:sudo chmod 777 iterm2login.sh
这里[lindex $argv 0], [lindex $argv 1], [lindex $argv 2], [lindex $argv 3] 分别代表着4个参数。分别是:端口号、用户名、服务器地址、密码。
注:expect "~" send "clear\n"此两行代码是登录完成后自动清除控制台信息。
配置iterm2的profiles,添加服务器信息,例如:
注:send text at start中填写五个参数,分别是:脚本 端口号 用户名 服务器地址 密码
如密码中带特殊字符,如‘@’时,会出现身份认证不通过,可在密码两端加上‘’
添加默认项,防止打开iterm2会自动链接某个服务器。
参考文件:http://blog.csdn.net/fenglailea/article/details/50895867