expect 實現iterm2自動加載pem登陸跳板機

#!/usr/bin/expect

set timeout 60
spawn ssh -i xx.pem user@59.151.78.78 -p 1715
expect {
"connecting (yes/no)?" { send "yes\r"; }
"passphrase for key" { send "password\r" }
}
interact

執行方法 sudo ~/skip/ssh-login.shhtml

#!/usr/bin/expect -f  
 set ip [lindex $argv 0 ]     //接收第一個參數,並設置IP  
 set password [lindex $argv 1 ]   //接收第二個參數,並設置密碼  
 set timeout 10                   //設置超時時間  
 spawn ssh root@$ip       //發送ssh請滶  
 expect {                 //返回信息匹配  
 "*yes/no" { send "yes\r"; exp_continue}  //第一次ssh鏈接會提示yes/no,繼續  
 "*password:" { send "$password\r" }      //出現密碼提示,發送密碼  
 }  
 interact          //交互模式,用戶會停留在遠程服務器上面. 

 

參考文章:https://www.cnblogs.com/lixigang/articles/4849527.html服務器

相關文章
相關標籤/搜索