FAQ
hi,

how to write a scripts which launches 10 pings to different
destinations at execution of single shell scripts

please help me any ideas

regards,
Gopinath

Search Discussions

  • Laurence Alexander Hurst at Jul 28, 2008 at 11:57 am

    Gopinath Achari wrote:
    hi,

    how to write a scripts which launches 10 pings to different
    destinations at execution of single shell scripts

    please help me any ideas

    regards,
    Gopinath
    Do you mean something like:
    ping -c10 host1
    ping -c10 host2
    ....
    which will ping host1 10 times, then host2 10 times etc. (see `man ping`
    for details of the options).

    If you have a list of hosts in a file, you could do:
    for host in `cat [filename]`
    do
    ping -c10 $host
    done

    or:

    while read host
    do
    ping -c10 $host
    done << [filename]

    If you only want to ping each host once, you can substitute '-c10' with
    '-c1' (again, see the man page).

    Hope this helps
    Laurence
  • Javor Nikolov at Jul 28, 2008 at 1:11 pm
    Hi,

    If you you want a quicker execution - you could also run the pings to
    separate hosts in parallel starting the jobs in background (&) and waiting
    for them with "wait" after that. You'll have to be more careful about the
    outputs in that case - e.g. redirect them to separate files.

    Regards,
    Javor
    On Mon, Jul 28, 2008 at 2:57 PM, Laurence Alexander Hurst wrote:

    Gopinath Achari wrote:
    hi,

    how to write a scripts which launches 10 pings to different
    destinations at execution of single shell scripts

    please help me any ideas

    regards,
    Gopinath
    Do you mean something like:
    ping -c10 host1
    ping -c10 host2
    ....
    which will ping host1 10 times, then host2 10 times etc. (see `man ping`
    for details of the options).

    If you have a list of hosts in a file, you could do:
    for host in `cat [filename]`
    do
    ping -c10 $host
    done

    or:

    while read host
    do
    ping -c10 $host
    done << [filename]

    If you only want to ping each host once, you can substitute '-c10' with
    '-c1' (again, see the man page).

    Hope this helps
    Laurence

    _______________________________________________
    CentOS mailing list
    CentOS@centos.org
    http://lists.centos.org/mailman/listinfo/centos
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.centos.org/pipermail/centos/attachments/20080728/6dbfa06e/attachment.htm
  • Gopinath Achari at Jul 29, 2008 at 5:09 am
    thank u all
    On Mon, 2008-07-28 at 16:11 +0300, Javor Nikolov wrote:
    Hi,

    If you you want a quicker execution - you could also run the pings to
    separate hosts in parallel starting the jobs in background (&) and
    waiting for them with "wait" after that. You'll have to be more
    careful about the outputs in that case - e.g. redirect them to
    separate files.

    Regards,
    Javor

    On Mon, Jul 28, 2008 at 2:57 PM, Laurence Alexander Hurst
    wrote:
    Gopinath Achari wrote:
    hi,

    how to write a scripts which launches
    10 pings to different
    destinations at execution of single shell scripts

    please help me any ideas

    regards,
    Gopinath
    Do you mean something like:
    ping -c10 host1
    ping -c10 host2
    ....
    which will ping host1 10 times, then host2 10 times etc. (see
    `man ping` for details of the options).

    If you have a list of hosts in a file, you could do:
    for host in `cat [filename]`
    do
    ping -c10 $host
    done

    or:

    while read host
    do
    ping -c10 $host
    done << [filename]

    If you only want to ping each host once, you can substitute
    '-c10' with '-c1' (again, see the man page).

    Hope this helps
    Laurence


    _______________________________________________
    CentOS mailing list
    CentOS@centos.org
    http://lists.centos.org/mailman/listinfo/centos



    _______________________________________________
    CentOS mailing list
    CentOS@centos.org
    http://lists.centos.org/mailman/listinfo/centos
  • Bill Campbell at Jul 28, 2008 at 3:36 pm

    On Mon, Jul 28, 2008, Gopinath Achari wrote:
    hi,

    how to write a scripts which launches 10 pings to different
    destinations at execution of single shell scripts

    please help me any ideas
    If your goal is to test connectivity, you might look at the perl
    Net::Ping module. ``perldoc Net::Ping'' has several examples of
    checking one or more systems to see if they are alive.

    BTW: Anybody know of a python equivalent to this?

    Bill
    --
    INTERNET: bill@celestial.com Bill Campbell; Celestial Software LLC
    URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
    Voice: (206) 236-1676 Mercer Island, WA 98040-0820
    Fax: (206) 232-9186

    A tax-supported, compulsory educational system is the complete model of the
    totalitarian state. -- Isabel Paterson, God of the Machine
  • Lorenzo Martínez Rodríguez at Jul 28, 2008 at 5:06 pm

    Bill Campbell escribi?:
    On Mon, Jul 28, 2008, Gopinath Achari wrote:

    hi,

    how to write a scripts which launches 10 pings to different
    destinations at execution of single shell scripts

    please help me any ideas
    If your goal is to test connectivity, you might look at the perl
    Net::Ping module. ``perldoc Net::Ping'' has several examples of
    checking one or more systems to see if they are alive.

    BTW: Anybody know of a python equivalent to this?

    Bill
    Hello,

    I have done something before with nmap -sP <target> time ago. Later you
    can grep the response to know whether an IP address is alive or not.

    Hope it helps,

    --



    Lorenzo Mart?nez Rodr?guez
    Consultor de seguridad inform?tica


    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.centos.org/pipermail/centos/attachments/20080728/1c77ab9e/attachment.htm
  • Mike at Jul 28, 2008 at 4:18 pm
    I really like 'fping' for use in shell scripts. See:
    http://www.fping.com/ and http://fping.sourceforge.net/man/

    It can be 'yum installed' from the CentOS RPMforge repo.

    So in your script you can just do
    fping -c 10 <dest1> <dest2> ... <destN>

    I don't understand exactly what 'scripts which launches 10 pings' and
    'execution of single shell scripts' means. So don't think I can help
    with the scripting part...
    On Mon, 28 Jul 2008, Gopinath Achari wrote:

    hi,

    how to write a scripts which launches 10 pings to different
    destinations at execution of single shell scripts

    please help me any ideas

    regards,
    Gopinath
  • Kapil singh at Jul 28, 2008 at 5:15 pm
    Hello,
    This is a running shell script for ping multiple host it provides result
    directly:
    if host is successfully ping then it returns Host is alive. otherwise Host
    is not alive
    Try this i am working with that in my local n/w.


    #/bin/bash
    for n in {1..5};
    do
    host2.168.1.$n
    ping -c2 $host &> /dev/null
    if [ $? = 0 ] ; then
    printf "%-30s is alive \n" $host
    else
    printf "%-30s is not alive \n" $host
    fi
    done


    Note: 1.Replace ip with your ip range
    2.Replace the no. of ip according to your need.(means value of n in for
    loop)




    --
    Thanks and Regards,
    Kapil Singh Kushwah
    Linux System Administrator
    Hotwax Media Inc.
    Indore,(M.P) INDIA
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.centos.org/pipermail/centos/attachments/20080728/61879a64/attachment.htm
  • Hywel Richards at Jul 30, 2008 at 6:50 am
    Can't resist posting the parallel version of this:

    #!/bin/bash
    if [ "$#" == "1" ]
    then
    ping -c2 $1 &> /dev/null
    if [ $? = 0 ] ; then
    printf "%-30s is alive \n" $1
    else
    printf "%-30s is not alive \n" $1
    fi
    else
    for n in $*
    do
    $0 $n &
    done
    wait
    fi


    This does the same thing as the parent post, but (a) takes the IP
    addresses as command-line arguments (i.e. call like this: "myscript
    192.168.1.1 192.168.1.2 192.168.1.3"), and (b) dispatches the pings in
    parallel so that you get the response from all the hosts quicker.

    The responses are displayed in the order they return, but you could put
    it through a sort if you wanted them ordered.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcentos @
categoriescentos
postedJul 28, '08 at 11:50a
activeJul 30, '08 at 6:50a
posts9
users8
websitecentos.org
irc#centos

People

Translate

site design / logo © 2021 Grokbase