Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I make the Linux ping to show the requests 'time out' instead of omitting the output?

Just like the Windows version of ping.

share|improve this question

migrated from serverfault.com Apr 12 '11 at 21:43

This question came from our site for professional system and network administrators.

5 Answers 5

I am afraid but there is no 100% solution to that with standard ping. Even with ping -v for verbose output ping would be silent in case of timeouts. You could try to use:

ping -w 2 192.168.199.1
PING 192.168.199.1 (192.168.199.1) 56(84) bytes of data.

--- 192.168.199.1 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1007ms

This would stop ping after 2 seconds and then show the number of packets transmitted and packet loss. Another option would be to use mtr.

share|improve this answer

There's no way for the common ping to do that. If you are trying to script something you have some options:

ping -c 2 <ip>
RESULT=$?
echo $RESULT
1

If the ping fails, $? will be 1, if the ping is successful, $? will be 0.

The other option is using fping that works a lot like Cisco ping:

$ fping 200.1.1.1
200.1.1.1 is unreachable
$ fping 192.168.1.1
192.168.1.1 is alive
share|improve this answer

When I use ping to see if a host is up in shell scripts, I do something like this:

ping -W 1 -c 1 $HOST 2>&1 > /dev/null || (echo -n "dead!"; false) && command-that-needs-host-to-be-up

Basically, sends one ICMP that times out in a second with no output and uses the exit code to gate further action.

share|improve this answer
nomad@local:~$ fping -l -e 8.8.8.8

8.8.8.8 : [0], 92 bytes, 183 ms (183 avg, 0% loss)
8.8.8.8 : [1], 92 bytes, 61.4 ms (122 avg, 0% loss)
8.8.8.8 : [2], 92 bytes, 164 ms (136 avg, 0% loss)
8.8.8.8 : [3], 92 bytes, 163 ms (143 avg, 0% loss)
8.8.8.8 : [5], 92 bytes, 158 ms (146 avg, 16% loss)
8.8.8.8 : [6], 92 bytes, 122 ms (142 avg, 14% loss)
8.8.8.8 : [7], 92 bytes, 134 ms (141 avg, 12% loss)
8.8.8.8 : [8], 92 bytes, 130 ms (140 avg, 11% loss)

nomad@local:~$ fping -version
fping: Version 3.2
fping: comments to david@schweikert.ch
share|improve this answer

fping did not work for me... In my case, most of the time I want to see this is basically during server rebooting... this works pretty nice on Windows...

I build a simple script (expanding @entropo answer) to help me on that, which may help answering this question:

https://gist.github.com/brunobraga/7259197

#!/bin/bash

host=$1

if [ -z $host ]; then
    echo "Usage: `basename $0` [HOST]"
    exit 1
fi

while :; do
    result=`ping -W 1 -c 1 $host | grep 'bytes from '`
    if [ $? -gt 0 ]; then
        echo -e "`date +'%Y/%m/%d %H:%M:%S'` - host $host is \033[0;31mdown\033[0m"
    else
         echo -e "`date +'%Y/%m/%d %H:%M:%S'` - host $host is \033[0;32mok\033[0m -`echo $result | cut -d ':' -f 2`"
        sleep 1 # avoid ping rain
    fi
done

And usage is something like:

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.