#!/bin/bash
#edit by www.jbxue.com
for a in {1..254}
do
if ping -w 1 -c 1 152.55.249.$a | grep "100%" >/dev/null
then
echo "152.55.249.$a is Not reachable"
else
echo "152.55.249.$a is reachable"
fi
done
解释:-w表示时间一秒,-c表示ping1次,如果返回100%,则表示失败输入到then语句,否则输入到else语句。
本文转自zsaisai 51CTO博客,原文链接:http://blog.51cto.com/3402313/1652737