ping.sh

  1. #!/bin/bash
  2. for i in {1..193}
  3. do
  4. ( ping -c1 -i0.2 -w1 172.16.30.$i &>/dev/null
  5. if (( $?==0 ))
  6. then
  7. echo "172.16.30.$i up" >>2.txt
  8. else
  9. echo "172.16.30.$i down" >>3.txt
  10. fi )& --》这样就把这一段放到后台去执行了,大大加快了速度。
  11. done
  12. sleep 2
  13. live_pc_num=`cat 2.txt|wc -l`
  14. down_pc_num=`cat 3.txt|wc -l`
  15. echo "there are $down_pc_num is down"
  16. echo "there are $live_pc_num is up"
  17. echo "list:"
  18. cat 2.txt
  19. rm -rf 2.txt 3.txt

break 停止循环


#!/bin/bash
i=1
while :
do
    echo "$i"
    (( i++ ))
    if ((  i==20000 )) --》输出的只有1-19999
    then
        break
    fi
done