Re: Bash Script Problem

From: Laura Darragh (sexygeek_at_pairowoodies.com)
Date: 11/04/03


Date: Tue, 04 Nov 2003 04:05:43 -0500

On Mon, 03 Nov 2003 10:55:11 +0000, WipeOut wrote:

> Laura Darragh wrote:
>> First, please please forgive me if this is not the correct newsgroup to
>> ask for help on this topic. But I can't seem to find any other
>> appropriate place. Hopefully, there's enough here that know about Bash
>> scripts that might be able to point me in the right direction.
>>
>> I came across a script which I'm trying to modify for my own environment -
>> the ping command gives a different output than the original script
>> I discovered.
>>
>> Here's the script:
>> *************************************
>> #!/bin/bash
>> # Report on network ping responses to determine health of devices on network.
>> # Ping Gateway
>> ping=`ping -c3 XXX.XXX.XXX.X | tail -2`
>> loss=`echo $ping |cut -d"," -f3 | cut -d"," -f1`
>> delay=`echo $ping | cut -d"=" -f2 | cut -d"/" -f1`
>>
>>
>> if [ "$loss" = "100% packet loss" ] ; then
>> echo router - XXX.XXX.XXX.X is not responding at all
>>
>> elif [ "$loss" != "0% packet loss" ] ; then
>> echo router - XXX.XXX.XXX.X is responding with packet loss
>>
>> else
>> if [ "$delay" -lt 100 ]; then
>> echo router - XXX.XXX.XXX.X is responding normally
>> else
>> echo router - XXX.XXX.XXX.X is responding slowly
>> fi
>> fi
>> *************************************
>>
>> Details:
>> XXX.XXX.XXX.X is an IP address of my router.
>>
>> When I run this script, the output is:
>> "echo router - XXX.XXX.XXX.X is responding with packet loss"
>>
>> But this should not be. The output in reality is 0% packet loss.
>>
>> And, during my experiments, I've even added an echo statement:
>> echo $loss
>>
>> Which always come back as "0% packet loss" which means that the first elif
>> statement should not be true. Yet the script is acting as if that
>> statement is true. And I've even ensured that the output is exactly "0%
>> packet loss" so there's no error there.
>>
>> So, I'm a bit stumped at this behaviour. Pulling my hair out trying to figure what could be wrong.
>>
>> Other details:
>> RH 9
>> Script created in Kate
>> Bash version: 2.05b.0(1)-release (i386-redhat-linux-gnu)
>>
>> Thanks guys.. any help would be appreciated. And if this is the wrong
>> place to ask this kind of question, I'm sorry.
>>
>> Laura
>
> I added..
>
> echo $loss
> echo $delay
>
> ..just below where you define these vars and get the following out put..
>
> +3 errors
> 3 packets transmitted, 0 received, +3 errors, 100% packet loss, time \
> 2019ms
>
> It looks like you are not getting the result you are testing for in the
> vars.. Thats my thought anyway..

Thanks for your thoughts, but you might be getting a different format of
ping response than I my version of ping.

At the command line, when I

ping -c3 XXX.XXX.XXX.X <substitute your own IP number here>

I get this:

PING XXX.XXX.XXX.X (XXX.XXX.XXX.X) 56(84) bytes of data.
64 bytes from XXX.XXX.XXX.X: icmp_seq=1 ttl=255 time=3.57 ms
64 bytes from XXX.XXX.XXX.X: icmp_seq=2 ttl=255 time=2.62 ms
64 bytes from XXX.XXX.XXX.X: icmp_seq=3 ttl=255 time=2.64 ms

--- XXX.XXX.XXX.X ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2016ms
rtt min/avg/max/mdev = 2.622/2.948/3.574/0.442 ms

My script only uses the last two lines. I've seen earlier versions of
ping that format these last two lines a bit differently. Perhaps that's
why you're seeing what you are?

Laura



Relevant Pages

  • Re: [SLE] emailing myself when a ping command fails via crontab????
    ... but I have a perl script to monitor a webserver. ... First the script tries to ping it's DNS servers, ...
    (SuSE)
  • RE: ICMP (Ping)
    ... script to locate vulnerabilities(example point and case: ... Is it good to allow UDP ping packets? ... Guys again, I am not saying that you disable pings and walk away, job ... 300K and you guys are right, it port scans like a freaking demon. ...
    (Security-Basics)
  • Trouble with Net::Ping
    ... And now here is what I get using ping manually: ... Approximate round trip times in milli-seconds: ... The manual execution of ping happened just before and just after my ... they are clearly accessable when manually invoking ping, the script ...
    (comp.lang.perl.misc)
  • Re: How to run script (sleep360) without delaying bootup
    ... I don't think they would mind Now the script you sent this morning which I don't have in front of me I would think could do the job. ... Maybe you could ping then see if there a command to dealy the time servers and then let them run. ... Pinging a server on the Internet isn't really the problem, ...
    (Fedora)
  • RE: Tools for pen test,
    ... You can use something like fping, but if your heart is set on a script, then ... The problem is that tools like PING ... I was wondering has anyone in here had a shell script that can execute tools ... Need to secure your web apps NOW? ...
    (Pen-Test)