死循环语句:
a=0 ;for ((;a<1))
>do
>command
>done
当a<1时,执行command,而a被定义成0。永远小于1。所以永远执行command。
指定执行条数:
for ((a=0;a<10;a++)); do command;done
上面的命令是只执行10次的表达方式
for中嵌套:
---------------------------
a=0;for ((;a<1;))
do
for num in $(seq 1 10)
do
ping -c 1 192.168.0.$num >ping
done
done
从192.168.0.1 ping到192.168.0.10 结束后,继续循环前面的动作。
---------------------------
用for查看存活主机:
for ((a=254;a>0;a--)); do ping -c 1 ping 192.168.0.$a>ping; done
--------------------------------------------------
for ((a=254;a>0;a--))
do
ping -c 1 192.168.0.$a > ping
done
--------------------------------------------------
==================================================
#!/bin/bash
#alive2.sh
#Checks to see if hosts 192.168.0.1-192.168.0.20 are alive
#Internet through Ip addresses
for n in {1..20}; do
host=192.168.0.$n
ping -c2 $host &> /dev/null
if [ $? = 0 ];then
echo "$host is UP"
else
echo"$host is DOWN"
fi
done
=================================================
阅读(326) | 评论(0) | 转发(0) |