一 实验要求
目前项目上线,有这样的需求,为了不让上线的服务器,不与线网的IP地址相冲突,写出一个shell脚本,把20.0.0.0/24网段在线的IP地址和不在线的IP地址列出来,并且保存到文档中
二 实验步骤
#!/bin/bash
for ((i=1; i<=254; i++))
do
ping -c 3 -i 0.2 -W 0.2 20.0.0.$i
if [ $? = 0 ]; then
echo "20.0.0.$i 在线" >> /opt/ipup.txt
else
echo "20.0.0.$i 不在线" >> /opt/ipdown.txt
fi
done