简体   繁体   中英

Linux Case statement using numbers

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 however $2 and $3 isnt working. any ideas?

code:
#!/bin/bash

while [ $# -lt 9000 ]
do
        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
       esac
done

and like the output could be like for example

letstrythisbash.sh 65-74
192.168.1.65 this one is up
192.168.1.69 this one is up
192.168.1.72 this one is up

You'll want a look at the seq command :

themel@kallisti: ~ $ for i in $(seq 69 73) ; do echo $i is a number ; done
69 is a number
70 is a number
71 is a number
72 is a number
73 is a number

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM