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 停止循环

  1. #!/bin/bash
  2. i=1
  3. while :
  4. do
  5. echo "$i"
  6. (( i++ ))
  7. if (( i==20000 )) --》输出的只有1-19999
  8. then
  9. break
  10. fi
  11. done