until测试远程主机连接
#!/usr/bin/bash
#
#v1.0 by kuibbaobao
ip=192.168.133.75
until ping -c1 -W1 $ip &>/dev/null //测试条件为假时循环
do
sleep 1
done
echo "&ip is up"
- for while until比较
- for脚本
#!/usr/bin/bash for i in {2..54} do { ip=192.168.122.$i ping -c1 -W1 $ip &>/dev/null if [ $? -eq 0 ];then echo "$ip up." fi }& done wait echo "all finish"
- while脚本
#!/usr/bin/bash i=2 while [ $i -le 254 ]; then do { ip=192.168.122.$i ping -c1 -W1 $ip &>/dev/null if [ $? -eq 0 ];then echo "$ip up" fi }& let i++ done wait echo "all finsh..."
- until脚本
#!/usr/bin/bash i=2 until [ $i -gt 254 ]; then do { ip=192.168.122.$i ping -c1 -W1 $ip &>/dev/null if [ $? -eq 0 ];then echo "$ip up" fi }& let i++ done wait echo "all finsh..."
- for脚本