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\r";exp_continue;} "*password:*" { send "$PASSWORD\r" } } interact
2:保存一个sh脚本,账号密码已参数形式传参
expect ~/Desktop/tzq/iterm2_config/item2Login.sh 端口 用户名 ip地址 密码
#!/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"} } interact
3.对于经常变更密码,对2进行了改良
expect /Users/ONE/Desktop/tzq/iterm2_config/item2Loginip.sh ip地址
#!/usr/bin/expect set timeout 30 spawn ssh -p 端口 用户名@[lindex $argv 0] expect { "(yes/no)?" {send "yes\n";exp_continue} "password:" {send "密码\n"} } interact