Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract average time from ping -c

Tags:

linux

bash

awk

ping

I want to extract from the command ping -c 4 www.stackoverflow.com | tail -1| awk '{print $4}' the average time.

107.921/108.929/110.394/0.905 ms

Output should be: 108.929

like image 367
creativeDev Avatar asked Mar 09 '12 13:03

creativeDev


People also ask

How long should a ping take?

In gaming, any amounts below a ping of 20 ms are considered exceptional and “low ping,” amounts between 50 ms and 100 ms range from very good to average, while a ping of 150 ms or more is less desirable and deemed “high ping.”

What is ping time output?

Ping (latency is the technically more correct term) means the time it takes for a small data set to be transmitted from your device to a server on the Internet and back to your device again. The ping time is measured in milliseconds (ms).


2 Answers

One way is to just add a cut to what you have there.

ping -c 4 www.stackoverflow.com | tail -1| awk '{print $4}' | cut -d '/' -f 2
like image 192
Buggabill Avatar answered Sep 20 '22 15:09

Buggabill


ping -c 4 www.stackoverflow.com | tail -1| awk -F '/' '{print $5}' would work fine.

"-F" option is used to specify the field separator.

like image 35
raj Avatar answered Sep 21 '22 15:09

raj