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

来源:互联网 发布:php trim 编辑:程序博客网 时间:2024/06/06 09:41
用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
原创粉丝点击