for_while_until_ping.sh
#!/usr/bin/bash
#for while until ping
#v1 by xfeng 2019.02.30
for i in {2..254}
do
{
ip=192.168.8.$i
The maximum duration of ping -c1 -W1 $ ip &> / dev / null # W1 represents the ping of 1s, c1 represents the number of ping
if [ $? -eq 0 ];then
echo “$ip is up...”
be
}&
the wait # {} & Representative performed simultaneously in the background, wait representing said background task execution before execution of the contents of the back
echo "All is finished"
done
while_for_until_ping.sh
i=2
while [ $i -le 254 ];do
{
ip=192.168.8.$i
The maximum duration of ping -c1 -W1 $ ip &> / dev / null # W1 represents the ping of 1s, c1 represents the number of ping
if [ $? -eq 0 ];then
echo “$ip is up...”
be
}&
let i++
done
until_while_for_ping.sh
i=2
until [ $i -gt 254];do
{
ip=192.168.8.$i
The maximum duration of ping -c1 -W1 $ ip &> / dev / null # W1 represents the ping of 1s, c1 represents the number of ping
if [ $? -eq 0 ];then
echo “$ip is up...”
be
}&
let i++
done