自动登录服务器 expect

ssh179

 1 #! /usr/bin/expect                                                                                                 
 2 set timeout 60
 3 set host 172.20.106.179
 4 set name [lindex $argv 0]
 5 set password abc123
 6 spawn ssh $name@$host 
 7 expect {
 8     "(yes/no)?" {
 9         send "yes\n" 
10         expect "password"
11         send "$password\n"
12     }
13     "password" {
14         send "$password\n"
15     }
16 }
17 interact

ssh53

 1 #! /usr/bin/expect                                                                                                 
 2 set timeout 60
 3 set host 172.20.106.53
 4 set name [lindex $argv 0]
 5 set password abc123
 6 spawn ssh $name@$host 
 7 expect {
 8     "(yes/no)?" {
 9         send "yes\n" 
10         expect "password"
11         send "$password\n"
12     }
13     "password" {
14         send "$password\n"
15     }
16 }
17 interact

ssh143

 1 #! /usr/bin/expect                                                                                                 
 2 set timeout 60
 3 set host 172.20.106.143
 4 set name [lindex $argv 0]
 5 set password abc123
 6 spawn ssh $name@$host 
 7 expect {
 8     "(yes/no)?" {
 9         send "yes\n" 
10         expect "password"
11         send "$password\n"
12     }
13     "password" {
14         send "$password\n"
15     }
16 }
17 interact

posted on 2013-06-05 22:42  阿加  阅读(193)  评论(0编辑  收藏  举报

导航