Ping Command

Is there a way for the ping command under Linux to behave like the Windows version when there are dropped packets...i.e. echo "request timed out" or something similar. Below is a script I have pieced together from various sources (as I am not a script master) to ping a given ip address and print a time stamp every 20 lines. My goal is to have it also echo the dropped packets to the log so that I can show packet loss in a time-frame reference. I have read the man page and tried every possible combination and it looks like it's going to come down to a bit of code.

ping -i 6 -c $count $ip | {

n=0
while read line
do
[ $n -eq 1 ] && date
printf "%s\n" "$line"
n=$(( ($n + 1) % 20 ))
done > ./$filename.txt
} &

---------------------/
Well, I'm not 100% sure of what you're trying to do, but I know that this:
ping www.google.com -w 2

Will wait 2 seconds after pinging, at which time it will exit, displaying summary info for the ping, including % dropped packets.
ping www.google.com -W 2

Is supposed to stop pinging that host after 2 seconds, but for some reason it doesn't work for me...

---------------------/
I would like for the output to resemble the windows version of ping...i.e.:

reply from ........
reply from ........
REQUEST TIMED OUT
REQUEST TIMED OUT
reply from ........
reply from ........

etc, etc.

---------------------/
"...ping www.google.com -W 2 is supposed to stop pinging that host after 2 seconds..."
You need to use a lower case "w" and not a capital "W":
ping www.google.com -w 2

---------------------/
When you ping in Linux you get:
PING www.google.akadns.net (64.233.161.99) 56(84) bytes of data.
64 bytes from 64.233.161.99: icmp_seq=1 ttl=242 time=33.0 ms
64 bytes from 64.233.161.99: icmp_seq=2 ttl=242 time=27.0 ms
64 bytes from 64.233.161.99: icmp_seq=3 ttl=242 time=25.8 ms

--- www.google.akadns.net ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2019ms
rtt min/avg/max/mdev = 25.857/28.639/33.029/3.140 ms
-

if a packet is dropped you will NOT see the echo on the screen in real time...you'll only know it when the ping is stopped and you get the summary of sent, received, lost, etc. I'm looking for a way to FORCE the ping command under Linux to behave like the ping command under Windows. Windows ping returns:

N:\>ping www.google.com

Pinging www.google.akadns.net [64.233.161.104] with 32 bytes of data:

Reply from 64.233.161.104: bytes=32 time=10ms TTL=243
Reply from 64.233.161.104: bytes=32 time=20ms TTL=243
Request timed out
Request timed out

Ping statistics for 64.233.161.104:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 10ms, Maximum = 20ms, Average = 17ms

the "-w" just tells ping to give up after a deadline isn't met. I want the test to run non-stop regardless of the result. If packets are answered...great. If not, I need to see the dropped packets with time stamps (as the original script posted shows). The time stamp issue has been solved. I now need to see the packet loss in real time. I frequently need to test internet connections for packet loss. Sometimes this packet loss only occurs at certain times of day.

---------------------/
$ wine ping.exe www.google.com

---------------------/
hmmmmmm...certainly a painfully obvious answer that I overlooked. But the question now is will it work with my script posted in the original question........

---------------------/
It should do although you will have to change the switch "-c $count" to "-n $count" and I don't think you can set the interval with DOS ping.

Have a Linux Problem
Linux Forum - Do you have a Linux Question?

Linux Books
Linux Certification, System Administration, Programming, Networking Books

Linux Home: Linux System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.