zoukankan      html  css  js  c++  java
  • for_while_until

    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

      ping -c1 -W1 $ip &>/dev/null    #W1代表ping的最大时长为1s,c1代表ping的次数

      if [ $? -eq 0 ];then

         echo “$ip is up...”

      fi

      }&

    wait                #{}&代表在后台同时执行,wait代表上述后台的任务执行后再执行后面的内容

    echo "All is finished"

    done

    while_for_until_ping.sh

    i=2

    while [ $i -le 254 ];do 

    {

      ip=192.168.8.$i

      ping -c1 -W1 $ip &>/dev/null    #W1代表ping的最大时长为1s,c1代表ping的次数

      if [ $? -eq 0 ];then

         echo “$ip is up...”

      fi

      }&

      let i++

    done

    until_while_for_ping.sh

    i=2

    until [ $i -gt 254];do

      {

      ip=192.168.8.$i

      ping -c1 -W1 $ip &>/dev/null    #W1代表ping的最大时长为1s,c1代表ping的次数

      if [ $? -eq 0 ];then

         echo “$ip is up...”

      fi

      }&

      let i++

    done

  • 相关阅读:
    iOS开源控件库收集
    Ruby中的几种除法
    Font
    PlaySound
    STL
    APIs
    cin and cout
    CreateWindow
    Introducing Direct2D
    VC 常用代码
  • 原文地址:https://www.cnblogs.com/xiaofeng666/p/12243752.html
Copyright © 2011-2022 走看看