码迷,mamicode.com
首页 > 其他好文 > 详细

批量主机探测秘钥分发

时间:2020-10-18 09:39:56      阅读:15      评论:0      收藏:0      [点我收藏+]

标签:ping   探测   $?   yum   pass   continue   lis   end   spawn   

#!/bin/bash
#by wwp 2020-10-14
#for openssh
>ip.list
passwd=6
rpm -q expect &>/dev/null
if [ $? -ne 0 ] ; then
yum -y install expect >/dev/null && echo "expect installed"
fi

if [ ! -f ~/.ssh/id_rsa ] ; then
ssh-keygen -P "" -f ~/.ssh/id_rsa
fi

for i in {130..180}
do
{
ip=192.168.188.$i
ping -c1 -W1 $ip &>/dev/null
if [ $? -eq 0 ];then
echo "$ip" >> ip.list
/usr/bin/expect <<-EOF
spawn ssh-copy-id $ip
expect {
"yes/no" { send "yes\r"; exp_continue }
"password:" { send "$passwd\r" }
}
expect eof
EOF
fi
}&
done
wait
echo "all finish"

批量主机探测秘钥分发

标签:ping   探测   $?   yum   pass   continue   lis   end   spawn   

原文地址:https://www.cnblogs.com/wwp01/p/13830437.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!