linuxfor循环-《shell脚本》

admin 2025-11-06 14:34:02 系统网络 来源:ZONE.CI 全球网 0 阅读模式
  • ping.sh
  • break 停止循环

    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
    01-shell脚本介绍-《shell脚本》 系统网络

    01-shell脚本介绍-《shell脚本》

    一、shell脚本是什么二、为什么要学shell,而不是其他计算机语言三、学习这门课程的优势四、学了能干什么五、学习什么内容六、学习的技巧七、成长路径八、学习环
    评论:0   参与:  12