LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-25-2013, 05:00 AM   #1
Buiosu
LQ Newbie
 
Registered: Sep 2013
Posts: 5

Rep: Reputation: Disabled
Unhappy Command line (ping) numbers precision


Hello,

on my Ubuntu Server 13.04 64b (only command line) when I'm pinging another network entity I have one digit after decimal separator for rtt, like this:
Code:
64 bytes from 10.10.10.2: icmp_seq=962 ttl=62 time=18.5 ms
(though summarized min/avg/max rtt is displayed with three digits after separator).

I need to have result with higher precision of rtt time, e.g.:
Code:
64 bytes from 10.10.10.2: icmp_seq=962 ttl=62 time=18.467 ms
How can I adjust this display precision?
Should I look for some locales or elsewhere?

I apologize, I'm a total newbie I agree. It's urgent for me however (MSc thesis measurements), and I didn't know how to explicitly google it (decimals, separators, precision, resolution, ping, linux, command line - all combined in many ways).

Regards.

Last edited by Buiosu; 09-25-2013 at 05:07 AM. Reason: 64b Linux
 
Old 09-25-2013, 07:50 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,133
Blog Entries: 10

Rep: Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827
LOL! It just works for me.

Sorry for that. I think it's merely the version of ping, took me a bit, I assumed "-v", then "--version", but it's Capital-V "ping -V", down at the bottom.

The other option is to grab the ping source and rewrite it to print with greater precision. I'd try to just get the correct copy of ping to suit your needs.

Make sure the one you're using is not derived from Busybox, that may be your problem.

Code:
ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.027 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.024 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.025 ms
^C
--- 127.0.0.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2997ms
rtt min/avg/max/mdev = 0.024/0.028/0.039/0.008 ms

ping -h
Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline]
            [-p pattern] [-s packetsize] [-t ttl] [-I interface or address]
            [-M mtu discovery hint] [-S sndbuf]
            [ -T timestamp option ] [ -Q tos ] [hop1 ...] destination

which ping
/bin/ping

ls -l /bin/ping
-rwsr-xr-x 1 root root 34756 2010-03-11 18:12 /bin/ping

ping -V
ping utility, iputils-sss20071127
Added: I'm using Ubuntu 12.10, so I guess they changed it for release 13. Not nice of them.

Last edited by rtmistler; 09-25-2013 at 07:52 AM.
 
Old 09-25-2013, 08:06 AM   #3
Buiosu
LQ Newbie
 
Registered: Sep 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
I've got iputils-sss20101006. So I'll connect it to the Internet and look for updates maybe (despite your version is older).
Regards.
 
Old 09-25-2013, 08:29 AM   #4
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Two ideas here. Either use the -D switch which prints the time with nanoseconds before each line. You maybe have to use the -i option to turn of wait intervall between packets. Or just subtract 1 seconds. Check man page for better overview.
Code:
[1380115547.971681] 64 bytes from 127.0.0.1: icmp_req=1 ttl=56 time=18.3 ms
[1380115547.989950] 64 bytes from 127.0.0.1: icmp_req=2 ttl=56 time=18.2 ms
Or you could use -c 1 option to just send one packet and then use the average numbers.
 
Old 09-25-2013, 09:31 AM   #5
Buiosu
LQ Newbie
 
Registered: Sep 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
Rtmistler, I've downgraded iputils-ping to your version but it didn't change anything.
I'll probably have to go on with zhjim's solution (-D +math) or to simply deal with smaller precision, while the issue remains unknown... But I'm still curious what is going on.

Regards.
 
Old 09-25-2013, 09:49 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,133
Blog Entries: 10

Rep: Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827
Here's your problem. From the iputils-s20101006 package, ping_common.c, function gather_statistics():

Code:
		if (timing) {
			if (triptime >= 100000)
				printf(" time=%ld ms", triptime/1000);
			else if (triptime >= 10000)
				printf(" time=%ld.%01ld ms", triptime/1000,
				       (triptime%1000)/100);
			else if (triptime >= 1000)
				printf(" time=%ld.%02ld ms", triptime/1000,
				       (triptime%1000)/10);
			else
				printf(" time=%ld.%03ld ms", triptime/1000,
				       triptime%1000);
		}
Your triptime is in excess of 10 mS so it's giving single digit precision in the print statement. To achieve greater precision in that case you would have to get rid of the "/100" and just use (triptime%1000) and change the %01ld to be %03ld.
 
2 members found this post helpful.
Old 09-26-2013, 04:48 AM   #7
Buiosu
LQ Newbie
 
Registered: Sep 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thumbs up [Solved] Command line (ping) numbers precision

Thanks a lot for your investigation!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I cannot ping with command 'ping IP' address but can ping with 'ping IP -I eth0' sanketmlad Linux - Networking 2 07-15-2011 05:32 AM
[SOLVED] Trying to number every other line and append those numbers to end of line kmkocot Programming 7 04-23-2010 11:17 AM
The date command and the height second precision hicham007 Programming 7 08-21-2006 08:11 AM
Grep's line numbers parsed into one line of output. judgex Programming 8 08-14-2006 04:22 AM
Simple question about command syntax ping/log ping results ohalnet Linux - Networking 1 07-25-2006 04:46 AM


All times are GMT -5. The time now is 07:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration