#!/bin/bash
SERVERS="172.17.xx.y 172.17.pp.mm"
PASSWORD=机器登录密码 auto_ssh_copy_file() {
expect -c "set timeout -1;
spawn scp -P登录端口 -r /main/文件目录 登录用户@$1:/main;
expect {
*(yes/no)* {send -- yes\r;exp_continue;}
*assword:* {send -- $2\r;exp_continue;}
eof {exit 0;}
}";
} # 循环所有的机器,开始copy
ssh_copy_id_to_all() {
for SERVER in $SERVERS
do
auto_ssh_copy_file $SERVER $PASSWORD
done
}
ssh_copy_id_to_all