复制密钥到目标机器
##1.shell脚本
#!/bin/sh
BASE_DIR=`dirname $0` && cd $BASE_DIR
function ssh_copy_id(){
for ip in `cat .ips-other`;do
expect auto-ssh-copy-id.exp $ip container `cat .password`
if [ $? -ne 0 ]; then
echo "免认证失败"
fi
done
}
##2.expect脚本
#!/usr/bin/expect
set timeout 5
set ip [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
#复制密钥到目标机器
spawn ssh-copy-id $user@$ip -p 1433
expect {
"yes/no" {send "yes\r";exp_continue;}
"password" {send "$password\r";exp_continue;}
}