一.分发脚本,通过scp -r -p 拷贝目录:
[oldboy@ser200 scripts]$ cat fefa.exp
#!/usr/bin/expect
#define var
set ip [lindex $argv 0]
set password "abcdef"
spawn scp -P20000 -p 批量分发ssh key-r /home/oldboy/.ssh oldboy@$ip:~
set timeout 60
expect {
-timeout 20
"yes/no" {send "yes\r"; exp_continue}
"*password:" {send "$password\r"}
timeout {puts "expect connect timeout, pls contact spyman"}
}
expect eof
exit
二.ip通过for 循环来获取
#!/bin/sh
for ip in `cat iplist`
do
expect /server/scripts/fefa.exp $ip
done
批量分发ssh key脚本比较简单。有待完善