for 循环比较IP是否可用,并将可用和非可用的IP保存下来,并通过scp协议传输文件
touch ip.txt res.txt for i in `seq 1 100` do sleep 3 ping -c 1 10.10.1.$i > /dev/null 2>&1 if [ $? -eq 0 ] then echo "${i} ping OK" >> res.txt echo "10.10.1.$i" >> ip.txt else echo "${i} ping NOTOK" >> res.txt fi done for i in `cat ip.txt` do ssh root@$i rm /etc/* scp file.zip root@$i:/etc ssh root@$i unzip /etc/file.zip done