Is there a way to tell ping to show its usual termination statistics without stopping the execution?
For instance, I’d like to quickly view:
--- 8.8.8.8 ping statistics --- 2410 packets transmitted, 2274 received, +27 errors, 5% packet loss, time 2412839ms rtt min/avg/max/mdev = 26.103/48.917/639.493/52.093 ms, pipe 3
without having to stop the program, thus losing the accumulated data.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
From the ping manpage (emphasis mine):
When the specified number of packets have been sent (and received) or if the program is terminated with a SIGINT, a brief summary is displayed. Shorter current statistics can be obtained without termination of process with signal SIGQUIT.
So this will work if you’re fine with your stats being slightly less verbose:
# the second part is only for showing you the PID ping 8.8.8.8 & jobs ; fg <... in another terminal ...> kill -SIGQUIT $PID
Short statistics look like this:
19/19 packets, 0% loss, min/avg/ewma/max = 0.068/0.073/0.074/0.088 ms
Method 2
There is one more easy way to get the ping statistics durning it’s execution:
Just press Ctrl + | (vertical slash or it’s also called pipe line)
I do personally use it very often, try it:
64 bytes from 192.168.1.1: icmp_seq=6 ttl=64 time=0.893 ms 64 bytes from 192.168.1.1: icmp_seq=23 ttl=64 time=0.862 ms 64 bytes from 192.168.1.1: icmp_seq=24 ttl=64 time=3.18 ms 64 bytes from 192.168.1.1: icmp_seq=35 ttl=64 time=0.877 ms 64 bytes from 192.168.1.1: icmp_seq=36 ttl=64 time=0.866 ms **36/36 packets, 0% loss, min/avg/ewma/max = 0.832/0.993/0.930/3.185 ms** 64 bytes from 192.168.1.1: icmp_seq=37 ttl=64 time=0.909 ms 64 bytes from 192.168.1.1: icmp_seq=38 ttl=64 time=2.03 ms 64 bytes from 192.168.1.1: icmp_seq=39 ttl=64 time=0.839 ms 64 bytes from 192.168.1.1: icmp_seq=40 ttl=64 time=0.880 ms
Method 3
On Mac it’s Ctrl+T.
Ctrl+ does the same as Ctrl+C, as it stops the ping after showing the stats.
Method 4
Linux (Tested on Ubuntu 20.04)
Send the SIGQUIT signal.
Example output:
64 bytes from localhost (127.0.0.1): icmp_seq=138 ttl=64 time=0.021 ms 64 bytes from localhost (127.0.0.1): icmp_seq=139 ttl=64 time=0.022 ms 139/139 packets, 0% loss, min/avg/ewma/max = 0.014/0.022/0.022/0.057 ms 64 bytes from localhost (127.0.0.1): icmp_seq=140 ttl=64 time=0.090 ms 64 bytes from localhost (127.0.0.1): icmp_seq=141 ttl=64 time=0.025 ms
Send while running
CTRL+ = quit according to stty -a.
These also work: CTRL+|; CTRL+4;
Send to one or more known pids
kill -SIGQUIT <pid> [...]
Send to all running
ps -o pid= -C ping | xargs -r kill -SIGQUIT
Periodically send to all running
while sleep 20; do ps -o pid= -C ping | xargs -r kill -SIGQUIT; done
As a background job
while sleep 20; do ps -o pid= -C ping | xargs -r kill -SIGQUIT; done &
FreeBSD (Tested on pfSense 2.4.5, based on FreeBSD 11.3)
Send the INFO signal.
Example output when sent via CTRL+T:
64 bytes from 127.0.0.1: icmp_seq=137 ttl=64 time=0.328 ms 64 bytes from 127.0.0.1: icmp_seq=138 ttl=64 time=0.028 ms load: 0.18 cmd: ping 62483 [select] 144.69r 0.00u 0.01s 0% 2256k 139/139 packets received (100.0%) 0.018 min / 0.072 avg / 0.505 max 64 bytes from 127.0.0.1: icmp_seq=139 ttl=64 time=0.116 ms 64 bytes from 127.0.0.1: icmp_seq=140 ttl=64 time=0.027 ms
Example output when sent via kill:
64 bytes from 127.0.0.1: icmp_seq=137 ttl=64 time=0.328 ms 64 bytes from 127.0.0.1: icmp_seq=138 ttl=64 time=0.028 ms 139/139 packets received (100.0%) 0.018 min / 0.072 avg / 0.505 max 64 bytes from 127.0.0.1: icmp_seq=139 ttl=64 time=0.116 ms 64 bytes from 127.0.0.1: icmp_seq=140 ttl=64 time=0.027 ms
Send while running
CTRL+T = status according to stty -a.
Send to one or more known pids
kill -INFO <pid> [...]
Send to all running
ps -o comm= -o pid= | egrep '^ping[[:space:]]' | awk -F' ' '{print $2}' | xargs -r kill -INFO
Periodically send to all running
printf "while ({ sleep 20 })nps -o comm= -o pid= | egrep '^ping[[:space:]]' | awk -F' ' '{print 442}' | xargs -r kill -INFOnendn" | tcsh
As a background job
printf "while ({ sleep 20 })nps -o comm= -o pid= | egrep '^ping[[:space:]]' | awk -F' ' '{print 442}' | xargs -r kill -INFOnendn" | tcsh &
Notes and Thanks
Thank you @pmos for your answer which seeded my idea for the periodic method in the first place, and to all the other answers and comments which contributed to this one.
Thank you @VictorYarema for making the suggestion that I turn my comment into an actual answer. The essence of the method in the original comment is the same, but has evolved over time as follows:
- Added the
-roption toxargsto prevent it from runningkillwithout a pid when there are no results fromps - To get rid of the header row in
psI used the-o pid=option to set the column header text to empty instead ofhsincehhas different meanings for Linux and FreeBSD- While
pssupports the explicit--no-headersoption in Linux, the same is not true for FreeBSD
- While
- Moved the
sleepcommand into thewhiletest condition - Removed unnecessary quotes
- Ported to FreeBSD
- Thanks to these answers which allowed me to write a one-liner while loop in tcsh which in turn required me to printf the $ used in
awk
- Thanks to these answers which allowed me to write a one-liner while loop in tcsh which in turn required me to printf the $ used in
Method 5
Try Ctrl+4
It shows a line like this:
312/312 packets, 0% loss, min/avg/ewma/max = 0.312/1.236/0.505/208.655 ms
Method 6
If your ping does not support a useful SIGQUIT (AIX, Solaris), here’s one workaround — an infinite ping loop where each ping only fires off (e.g.) 10 pings, so that you can see intermediate results.
while :; do ping -c 10 $HOST; done
To stop it, Control-C may only kill the ping command; you may need to suspend and then kill the job (Control-z; kill %).
This of course does not provide true running statistics — just over the course of those 10 pings.
Method 7
You can use watch utility
watch -n 3 ping -c 1 10.170.0.21
That will run the ping command every 3 seconds and show you the output continuously.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0