在堡垒机上 自动登录其它机子的 shell(expect)

直接上代码

 1 #!/usr/bin/expect -f
 2 if {$argc < 1} {
 3     send_user "Usage:\n  $argv0 IPaddr User Passwd Port Passphrase\n"
 4     puts stderr "argv error!\n"
 5     sleep 1
 6     exit 1
 7 }
 8 
 9 set ip         [lindex $argv 0 ]
10 set user       [lindex $argv 1 ]
11 set passwd     [lindex $argv 2 ]
12 set port       [lindex $argv 3 ]14 set timeout 6
15 if {$port == ""} {
16     set port 22
17 }
18 if {$user == ""} {
19     set user "你的通用帐号"
20 }
21 if {$passwd == ""} {
22     set passwd "通用帐号匹配的密码"
23 }
25 spawn ssh -p $port $user@$ip
26 expect {
27       "yes/no" { send "yes\n";exp_continue }
28       "password" { send "$passwd\n" }
29 }
33 interact
34 #echo -e "\033[?25h"

 

posted on 2020-09-16 09:36  旧楚布衣  阅读(243)  评论(0编辑  收藏  举报