目录

Expect批量添加ssh免密登录

编写脚本deploy_ssh_key.exp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/usr/bin/expect -f

set timeout 2
set ipaddress [lindex $argv 0]
set passwd "password"

spawn ssh-copy-id "-p2522 mds@$ipaddress"

expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "$passwd\r" }
}
expect "#"

批量执行

for x in cat ip.txt | awk ‘{print $1}‘;do ./deploy_ssh_key.exp $x;done