一.分發腳本,通過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腳本比較簡單。有待完善