Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Post Bash case statement help

    Hi i'm trying to make a small script
    i would like to ping to my subnet from a certain number till another certain number for example

    while [ $# -lt 9000 ]
            case "$1" in 
            -$2-3) for i in 192.168.1.{$2..$3];do if ping -c1 -w1 &>/dev/null;then echo $i this one is up;fi; done
            shift shift;;
            -a) echo "hey just something random
    and like the output could be like for example 65-74 this one is up this one is up this one is up

  2. #2
    must you use case? you could do what you want w/a loop like this:

    # get args from command line
    # make sure it is in the form of "N-N"
    echo $args|grep -q ^[0-9][0-9]*-[0-9][0-9]*$
    if [ $? -ne 0 ]; then
      echo "
      Usage: $0 <FIRST_OCTET>-<LAST_OCTET>
       E.g.: $0 5-10
      exit 1
    # split up into first and last number (octets of ip address)
    first=$(echo $1|cut -f1 -d-)
    last=$(echo $1|cut -f2 -d-)
    # duh
    if [ $first -gt $last ]; then
      echo first number must be less than second number
      exit 1
    # the loop
    for ((i=$first;i<=$last;i++)); do
      echo ping $ip

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts