profiles =》open profiles => edit profiles
1:如图每一连接信息保存单独的文件
set PORT 22 set HOST 10.***.***.** set USER ******** set PASSWORD ******** spawn ssh -p $PORT $USER@$HOST expect { "yes/no" {send "yes ";exp_continue;} "*password:*" { send "$PASSWORD " } } interact
2:保存一个sh脚本,账号密码已参数形式传参
expect ~/Desktop/tzq/iterm2_config/item2Login.sh 端口 用户名 地址 密码
#!/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