您的位置:首页 > 运维架构 > Shell

用shell脚本批量分发公钥,实现用…

2017-07-15 16:00 92 查看
用shell脚本批量分发公钥(将所有),先创建密钥分发expetc脚本key.exp
再创建shell脚本,调用expetc
1.vim ip.txt
10.1.1.1
10.2.2.2
10.3.3.3

2.key.exp
vim key.exp
#!/usr/bin/expetc
set timeout 300
set password "redhat"
set ip [lindex $argv 0]
spawn ssh-copy-id root@$ip
expetc{
"yes/no"{
send "yes\r"
exp_continue
}
"password: "{
send"password\r"
exp_continue
}
eof;
}

再创建shell脚本,调用expetc
3.
vim distribute.exp
#!/bin/bash
./etc/init.d/functions
for i in 'cat /root/ip.txt';do
expetc /root/key.exp $i>/dev/null 2>&1
if[$? -eq 0];then
action"$i" /bin/true
else
action "$i"/bin/false
fi
done
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: