併發取網段的ip地址並生成ansible的hosts

配置文件分ip和ansible_hosts,生成完成後需手動導入以免報錯

#!/bin/bash
Usage(){
echo $"USAGRE:/bin/bash $0"
exit 1
}
if [ "$#" -ne "0" ];then
Usage
fi
CMD="ping -w 2 -c 2"
IP="192.168.1."
for n in `seq 1 254`
do
  {
$CMD $IP$n &> /dev/null
if [ $? -eq 0 ];then
echo "$IP$n" >> /root/ip
fi
  }&
done
sleep 3
for i in `cat /root/ip`
do
echo "$i  ansible_ssh_host=$i ansible_ssh_user=root ansible_ssh_pass=密碼 ansible_ssh_port=22" >> ansible_hosts
done
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章