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