]$ cat host
mgmt
]$ cat ip.txt
hp-cn01
hp-cn02
hp-cn03
hp-cn04
hp-cn05
hp-cn06
hp-cn07
hp-cn08
第一次只有一个主机ssh,第二次有2个主机ssh,第三次有4个主机ssh,第四次有8个主机ssh
#!/bin/bash
k=1
while [ 1 -gt 0 ]
do
if [ -e host ]
then
num=`cat host|wc -l`
if [ $num -eq 9 ]
then
exit 0
fi
num_ip=`cat ip.txt|wc -l`
if [ $num_ip -eq 0 ]
then
break
fi
if [ $num -eq $k ]
then
mv host host1
count=$k
while [ 1 -gt 0 ]
do
num_ip1=`cat ip.txt|wc -l`
if [ $num_ip1 -eq 0 ]
then
break
fi
h1=`head -n 1 host1`
p1=`head -n 1 ip.txt`
sed -i "1d" ip.txt
sed -i "1d" host1
echo "${h1}----${p1}"
ssh ${p1} "sleep 3" && echo -e "${h1}\n${p1}" >>host &
let count=count-1
if [ $count -eq 0 ]
then
break
fi
done
let k=k+k
fi
fi
done
while [ 1 -gt 0 ]
do
if grep 'hp-cn08' host >/dev/null
then
echo "ok"
break
fi
done