Scripting with arguments for ping command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripting with arguments for ping command
# 1  
Old 05-23-2015
Scripting with arguments for ping command

This is the script I already have but I have problems with two arguments
the first argument -t , I want to count 200 by the last digit of the IP address for example when I run the script ./ping.sh -t 17, the output would be
Code:
192.168.0.217 is up

The second arguments --up won't work. Could anybody help me please with these two arguments?
Code:
#!/bin/bash

while [[ -n "$@" ]]
do
    case "$1" in

    -h|--help)
    Extension=1
    shift
    ;;

    -XX-YY)
    Extension=2
    shift
    min=$1
    shift
    max=$1
    shift
    
    ;;

    --up)
    Extension=3
    shift
    end=$1
    shift
    ;;
    esac
done

if [ "$Extension" -eq 1 ] ; then

    echo "dit is de help"

fi


if [ "$Extension" -eq 2 ] ; then

for ((n=$min ; n<=$max ; n+=1))
do
ip=192.168.129.$n
if ping -c 1 -w 1 ${ip} > /dev/null 2> /dev/null >> logping.txt; then
echo "${ip} is up"
else
echo "${ip} is down"
fi
done


fi

if [ "$Extension" -eq 3 ] ; then

         
  
               ip=192.168.129.$end
                if ping -c 1 -w 1 ${ip} > /dev/null 2> /dev/null >> /logping.txt; then
                        echo "${ip} is up"
                       
                fi
     
fi


Last edited by rbatte1; 05-26-2015 at 12:43 PM.. Reason: Added CODE & ICODE tags in main paragraph. Corrected spelling, grammer and case.
# 2  
Old 05-23-2015
Not sure I understand what your problem is (on top of that Don Cragun already proposed a decent solution to your request in your other thread)
In above snippet, you don't parse for the -t option, so I don't see what you'd expect that could go wrong. Were -t present, just add your 200 to min and max...
What behaviour would you expect for your --up option?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ping scripting

This is my first posting here, I haven't found exactly what I'm looking for anywhere else so I'm hoping you all can help. I have a portion of script here that needs to ping two servers, then return whether they are up or down (somehow), and then echo that information. Here is what I have so far. It... (3 Replies)
Discussion started by: Jeffm0342
3 Replies

2. UNIX for Beginners Questions & Answers

Beginner at bash scripting - need help with passing arguments

I at the moment, making a simple bash script, capable of setting up an workspace for me, so i don't have to do it manually.. Problem is though i can't seem to provide the bash script any argument, without running into my error checks, checking for input... Here is the code: #!/bin/bash... (7 Replies)
Discussion started by: kidi
7 Replies

3. Shell Programming and Scripting

Shell scripting with passing arguments

Hi All, I am using the script for creating local queue and passing the arguments while running the script as below n=0 while do e=`expr $n + 3` echo 'DEFINE QL('$e') MAXDEPTH('$6') MAXMSGL('$7') DEFPSIST('$8') '$9'' | /apps/mqm_opt/bin/runmqsc $2 n=`expr $n + 1` done Running the... (5 Replies)
Discussion started by: Anusha M
5 Replies

4. Homework & Coursework Questions

Shell Scripting with Arguments

1. The problem statement, all variables and given/known data: Problem 1: I need to create a shell script the takes three arguments and echo's out "There once was a ____that____who like to_____" The arguments go where the blanks are. Problemt 2: -Do an LS and store the... (4 Replies)
Discussion started by: dw15
4 Replies

5. Shell Programming and Scripting

Help with Ping command.

Hi, I have a shell script, that has to run in putty for days together. So , I need to keep the network server connection alive and running. The execution of shell script shouldn't be interrupted as it produces undesirable results. Can anyone provide me with a script ? (3 Replies)
Discussion started by: angie1234
3 Replies

6. UNIX for Dummies Questions & Answers

Help on ping command

Hi, I have a list of 500 IP address and need to ping all the IP address. I had written a script to do this and its working if the IP is valid one. If any invalid IP present, the process got hang up. Also I have tried with -c , -I and -w options, its not working. Any one help me on this... (2 Replies)
Discussion started by: Rksiva
2 Replies

7. AIX

Problem with 'ping' command

Hi All, I'm testing ping command on two servers. A,B,C,D are servers From A-->B: ping -c 3 -p ff -s30720 <B IP-Addres> This works fine. From C-->D: ping -c 3 -p ff -s30720 <D IP-Addres> This is NOT working and 100% packe loss :( But if I use 8700 instead of 30720 for packet size... (6 Replies)
Discussion started by: saraperu
6 Replies

8. UNIX for Dummies Questions & Answers

Ping command

Hello Everybody: Im the root of the system, I need to grant some limited priviliges user an acess to the ping command so he can ping some IPs with his script. should I add the command to his path?? or what?? Thanks a lot (3 Replies)
Discussion started by: aladdin
3 Replies

9. IP Networking

About ping command

Hi! I have small problem. I want to ping a server and the result shouldn't be printed in the browser window, just become a value. Here you can see the script that I have: $command="ping linux.com -t ttl -c1 | tail -1 | awk '{print $4 \" \" $5}'"; $output = system($command); ... (2 Replies)
Discussion started by: Papa Deoo
2 Replies

10. UNIX for Dummies Questions & Answers

About ping command

Hi! I have small problem. I want to ping a server and the result shouldn't be printed in the browser window, just become a value. Here you can see the script that I have: <? $command="ping linux.com -t ttl -c1 | tail -1 | awk '{print $4 \" \" $5}'"; $output = system($command);... (1 Reply)
Discussion started by: Papa Deoo
1 Replies
Login or Register to Ask a Question