Problems with past arguments in script

Discussion in 'Programming/Scripts' started by Rasp, May 20, 2015.

  1. Rasp

    Rasp New Member

    I have a question is there any possibility for maken a script that you can see if computers are on in your network
    when you run the script for ex. ./ping.sh 54 62 62 , a script when you give as argument the last digit of the ip adres of the computers

    my network is 192.168.129.0

    This is what i already have but i want to give extra parameters to the script
    for example
    parameter 1: xx-yy: this parameter ensures that all computers be test in the range of xx-yy eg. 61-67, test all the 7 computers with the last digit

    parameter 2: -t , ensures that each number count with 200 eg. -t 17 test the ip adress 217 , -t 17-19 test all the adresses 217 to 219

    1. for ip in192.168.1.{1..10};do# for loop and the {} operator
    2. ping -c 1-t 1192.168.1.1>/dev/null 2>/dev/null # ping and discard output
    3. if[ $?-eq 0];then# check the exit code
    4. echo "${ip} is up"# display the output
    5. else
    6. echo "${ip} is down"
    7. fi
    8. done
     
  2. sjau

    sjau Local Meanie Moderator

    I use:

    Code:
    #!/usr/bin/env bash
    
    network=${1}
    
    is_alive()
    {
        ping -b -c 1 ${i} > /dev/null
        [[ $? -eq 0 ]] && echo "${i} is up"
    }
    
    for i in ${network}.{0..254}
    do
        is_alive ${i} & disown
    done
    
    ./ping.sh 10.0.0
     

Share This Page