How to command “Ping” display time and date of ping












32















When I ping I have this display:



> ping -i 4 www.google.fr 
64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=503 ttl=46 time=45.5 ms
.......
.......
64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=508 ttl=46 time=44.9 ms
64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=509 ttl=46 time=45.1 ms


I'd like to have the time of the ping before.



Something like:



> (right functions) + ping -i 7 www.google.fr 
mardi 15 mai 2012, 10:29:06 (UTC+0200) - 64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=503 ttl=46 time=45.5 ms
.......
.......
mardi 15 mai 2012, 10:29:13 (UTC+0200) - 64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=508 ttl=46 time=44.9 ms
mardi 15 mai 2012, 10:29:20 (UTC+0200) - 64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=509 ttl=46 time=45.1 ms


How would you do this in a command line (if it's possible)?










share|improve this question

























  • Generic version – Is there a Unix utility to prepend timestamps to stdin?

    – Piotr Dobrogost
    Jan 1 at 21:44


















32















When I ping I have this display:



> ping -i 4 www.google.fr 
64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=503 ttl=46 time=45.5 ms
.......
.......
64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=508 ttl=46 time=44.9 ms
64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=509 ttl=46 time=45.1 ms


I'd like to have the time of the ping before.



Something like:



> (right functions) + ping -i 7 www.google.fr 
mardi 15 mai 2012, 10:29:06 (UTC+0200) - 64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=503 ttl=46 time=45.5 ms
.......
.......
mardi 15 mai 2012, 10:29:13 (UTC+0200) - 64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=508 ttl=46 time=44.9 ms
mardi 15 mai 2012, 10:29:20 (UTC+0200) - 64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=509 ttl=46 time=45.1 ms


How would you do this in a command line (if it's possible)?










share|improve this question

























  • Generic version – Is there a Unix utility to prepend timestamps to stdin?

    – Piotr Dobrogost
    Jan 1 at 21:44
















32












32








32


10






When I ping I have this display:



> ping -i 4 www.google.fr 
64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=503 ttl=46 time=45.5 ms
.......
.......
64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=508 ttl=46 time=44.9 ms
64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=509 ttl=46 time=45.1 ms


I'd like to have the time of the ping before.



Something like:



> (right functions) + ping -i 7 www.google.fr 
mardi 15 mai 2012, 10:29:06 (UTC+0200) - 64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=503 ttl=46 time=45.5 ms
.......
.......
mardi 15 mai 2012, 10:29:13 (UTC+0200) - 64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=508 ttl=46 time=44.9 ms
mardi 15 mai 2012, 10:29:20 (UTC+0200) - 64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=509 ttl=46 time=45.1 ms


How would you do this in a command line (if it's possible)?










share|improve this question
















When I ping I have this display:



> ping -i 4 www.google.fr 
64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=503 ttl=46 time=45.5 ms
.......
.......
64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=508 ttl=46 time=44.9 ms
64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=509 ttl=46 time=45.1 ms


I'd like to have the time of the ping before.



Something like:



> (right functions) + ping -i 7 www.google.fr 
mardi 15 mai 2012, 10:29:06 (UTC+0200) - 64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=503 ttl=46 time=45.5 ms
.......
.......
mardi 15 mai 2012, 10:29:13 (UTC+0200) - 64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=508 ttl=46 time=44.9 ms
mardi 15 mai 2012, 10:29:20 (UTC+0200) - 64 bytes from wi-in-f94.1e100.net (173.194.67.94): icmp_seq=509 ttl=46 time=45.1 ms


How would you do this in a command line (if it's possible)?







command-line ping






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 15 '12 at 9:17









Achu

15.9k136499




15.9k136499










asked May 15 '12 at 8:30









Olivier PonsOlivier Pons

5584918




5584918













  • Generic version – Is there a Unix utility to prepend timestamps to stdin?

    – Piotr Dobrogost
    Jan 1 at 21:44





















  • Generic version – Is there a Unix utility to prepend timestamps to stdin?

    – Piotr Dobrogost
    Jan 1 at 21:44



















Generic version – Is there a Unix utility to prepend timestamps to stdin?

– Piotr Dobrogost
Jan 1 at 21:44







Generic version – Is there a Unix utility to prepend timestamps to stdin?

– Piotr Dobrogost
Jan 1 at 21:44












6 Answers
6






active

oldest

votes


















60














Use:



ping www.google.fr | while read pong; do echo "$(date): $pong"; done


You will get the result like this:



enter image description here






share|improve this answer





















  • 1





    Wow very nice. And helpful to learn shell stuff. Thank you!

    – Olivier Pons
    May 15 '12 at 9:54



















12














Another possibility to use the ping -D option which gets you the timestamp as Unix time.



tilo@t-ubuntu:~$ ping google.com -D
PING google.com (173.194.33.73) 56(84) bytes of data.
[1388886989.442413] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=1 ttl=57 time=11.1 ms
[1388886990.443845] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=2 ttl=57 time=11.0 ms
[1388886991.445200] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=3 ttl=57 time=10.8 ms
[1388886992.446617] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=4 ttl=57 time=10.9 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 10.860/11.005/11.139/0.123 ms
tilo@t-ubuntu:~$


Here a version of "Achu" command with slightly different format:



ping www.google.com -i 10 -c 3000 | while read pong; do echo "$(date +%Y-%m-%d_%H%M%S): $pong"; done >PingTest_2014-01-04.log


That gets you:



2014-01-04_175748: 64 bytes from sea09s16-in-f19.1e100.net (173.194.33.115): icmp_req=13 ttl=57 time=10.5 ms





share|improve this answer

































    2














    You can also use gawk (or awk, if your /etc/alternatives/awk points to /usr/bin/gawk):



    ping -c 4 www.google.fr | gawk '{print strftime("%c: ") $0}'


    This is similar to the approach in Achu's answer, but ping's output is piped to gawk instead of a shell loop that calls date. As with that approach, it works without -c, but if you don't pass -c n to make ping stop after n pings, and you stop the loop with Ctrl+C, ping won't print the usual statistics.



    ek@Io:~$ ping -c 4 www.google.fr | gawk '{print strftime("%c: ") $0}'
    Tue 03 Jan 2017 10:09:51 AM EST: PING www.google.fr (216.58.193.99) 56(84) bytes of data.
    Tue 03 Jan 2017 10:09:51 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=1 ttl=51 time=327 ms
    Tue 03 Jan 2017 10:09:52 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=2 ttl=51 time=302 ms
    Tue 03 Jan 2017 10:09:53 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=3 ttl=51 time=282 ms
    Tue 03 Jan 2017 10:09:54 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=4 ttl=51 time=349 ms
    Tue 03 Jan 2017 10:09:54 AM EST:
    Tue 03 Jan 2017 10:09:54 AM EST: --- www.google.fr ping statistics ---
    Tue 03 Jan 2017 10:09:54 AM EST: 4 packets transmitted, 4 received, 0% packet loss, time 3003ms
    Tue 03 Jan 2017 10:09:54 AM EST: rtt min/avg/max/mdev = 282.035/315.227/349.166/25.398 ms


    ek@Io:~$ ping www.google.fr | gawk '{print strftime("%c: ") $0}'
    Tue 03 Jan 2017 10:10:35 AM EST: PING www.google.fr (216.58.193.99) 56(84) bytes of data.
    Tue 03 Jan 2017 10:10:35 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=1 ttl=51 time=305 ms
    Tue 03 Jan 2017 10:10:35 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=2 ttl=51 time=365 ms
    Tue 03 Jan 2017 10:10:36 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=3 ttl=51 time=390 ms
    Tue 03 Jan 2017 10:10:38 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=4 ttl=51 time=824 ms
    Tue 03 Jan 2017 10:10:38 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=5 ttl=51 time=287 ms
    ^C


    This happens whether ping's output is piped to gawk or a shell while loop. The reason is that command on the right side of the pipe, rather than ping, receives SIGINT when Ctrl+C is pressed, and ping does not know to print the statistics before being terminated.



    If you have run ping without -c on the left side of a pipe (as shown above) and you want to terminate it in such a way that it still prints the statistics, then instead of pressing Ctrl+C in the terminal where it is running, you could run kill -INT PID from another terminal, replacing PID with the process ID of the ping command. If you're only running one instance of ping then you could simply use killall -INT ping.



    Alternatively, you could replace the ping command on the left side of the pipe with a command that runs a shell, reports the process ID of that shell, and then replaces that shell with the ping command (causing it to have the same PID):



    sh -c 'echo $$; exec ping www.google.fr' | gawk '{print strftime("%c: ") $0}'


    Then the first line of output, will show the process ID of the ping command (which will typically be different each time). It would look like this, but with a different time and date and probably a different process ID:



    Tue 20 Mar 2018 12:11:13 PM EDT: 7557


    Then, from another terminal, you can run kill -INT 7557, replacing 7557 with the actual process ID you saw, to terminate the ping command in such a way as to cause it to print statistics.



    (If you take advantage of your shell's job control features, then you can achieve this within the same terminal, too. But if you want to copy text from your terminal without having to remove any extranous part where you ran commands in that terminal, then you should terminate ping from a separate terminal.)



    Further reading:





    • Alin's answer to How to derive current date and time and append at the end of each line that contain 'Hello' on Stack Overflow.


    • 9.1.5 Time Functions in Gawk: Effective AWK Programming (Gawk's official reference manual).


    • man ping - "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."






    share|improve this answer


























    • is there a way to send ctrl+c to ping first?

      – atti
      Mar 20 '18 at 12:04






    • 1





      @atti Yes, you can send SIGINT (which is what pressing Ctrl+C does) to the ping process specifically, using kill or killall. I've expanded this answer with details.

      – Eliah Kagan
      Mar 20 '18 at 17:00



















    1














    There is a utility called 'ts', which reads stdin, adds timestamps, and writes it to stdout:




    me@my-laptop:~$ ping localhost | ts
    Nov 08 09:15:41 PING localhost (127.0.0.1) 56(84) bytes of data.
    Nov 08 09:15:41 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.060 ms
    Nov 08 09:15:42 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.098 ms
    Nov 08 09:15:43 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.082 ms
    Nov 08 09:15:44 64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.091 ms






    share|improve this answer































      0














      ping google.in | xargs -n1 -i bash -c 'echo `date +"%Y-%m-%d %H:%M:%S"`" {}"'


      If your interested in saving it in file, then type the below command in the terminal



      ping google.in | xargs -n1 -i bash -c 'echo `date +"%Y-%m-%d %H:%M:%S"`" {}"' >> "/home/name_of_your_computer/Desktop/Ping_Test.txt"


      You don't need to create any text files, it'll automatically do



      Ping_Test.txt



      2018-04-19 15:35:53 PING google.in (216.58.203.164) 56(84) bytes of data.
      2018-04-19 15:35:53 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=1 ttl=57 time=23.0 ms
      2018-04-19 15:35:53 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=2 ttl=57 time=38.8 ms
      2018-04-19 15:35:54 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=3 ttl=57 time=32.6 ms
      2018-04-19 15:35:55 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=4 ttl=57 time=22.2 ms
      2018-04-19 15:35:56 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=5 ttl=57 time=22.1 ms
      2018-04-19 15:35:59 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=7 ttl=57 time=23.6 ms
      2018-04-19 15:36:00 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=8 ttl=57 time=22.6 ms
      2018-04-19 15:36:01 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=9 ttl=57 time=22.3 ms
      2018-04-19 15:36:02 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=10 ttl=57 time=26.3 ms





      share|improve this answer































        -1














        (thanks to Achu and Eliah Kagan for the ideas)
        there's a way to




        • add time to ping output

        • keep footnotes of ping

        • and terminate this whole construction with ctrl+c


        to do this one should instruct right part of the command (after the pipe) to ignore SIGINT using trap "" INT:



        $ ping www.google.fr | bash -c 'trap "" INT; awk "{print strftime("%c - ") $0}"'  
        lun 26 Mar 2018 22:05:08 +0300 - PING www.google.fr (173.194.73.94) 56(84) bytes of data.
        lun 26 Mar 2018 22:05:08 +0300 - 64 bytes from lq-in-f94.1e100.net (173.194.73.94): icmp_seq=1 ttl=47 time=19.6 ms
        lun 26 Mar 2018 22:05:09 +0300 - 64 bytes from lq-in-f94.1e100.net (173.194.73.94): icmp_seq=2 ttl=47 time=20.1 ms
        ^Clun 26 Mar 2018 22:05:09 +0300 -
        lun 26 Mar 2018 22:05:09 +0300 - --- www.google.fr ping statistics ---
        lun 26 Mar 2018 22:05:09 +0300 - 2 packets transmitted, 2 received, 0% packet loss, time 1000ms
        lun 26 Mar 2018 22:05:09 +0300 - rtt min/avg/max/mdev = 19.619/19.866/20.114/0.284 ms





        share|improve this answer

























          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "89"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f137233%2fhow-to-command-ping-display-time-and-date-of-ping%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          6 Answers
          6






          active

          oldest

          votes








          6 Answers
          6






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          60














          Use:



          ping www.google.fr | while read pong; do echo "$(date): $pong"; done


          You will get the result like this:



          enter image description here






          share|improve this answer





















          • 1





            Wow very nice. And helpful to learn shell stuff. Thank you!

            – Olivier Pons
            May 15 '12 at 9:54
















          60














          Use:



          ping www.google.fr | while read pong; do echo "$(date): $pong"; done


          You will get the result like this:



          enter image description here






          share|improve this answer





















          • 1





            Wow very nice. And helpful to learn shell stuff. Thank you!

            – Olivier Pons
            May 15 '12 at 9:54














          60












          60








          60







          Use:



          ping www.google.fr | while read pong; do echo "$(date): $pong"; done


          You will get the result like this:



          enter image description here






          share|improve this answer















          Use:



          ping www.google.fr | while read pong; do echo "$(date): $pong"; done


          You will get the result like this:



          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 14 at 7:53

























          answered May 15 '12 at 9:04









          AchuAchu

          15.9k136499




          15.9k136499








          • 1





            Wow very nice. And helpful to learn shell stuff. Thank you!

            – Olivier Pons
            May 15 '12 at 9:54














          • 1





            Wow very nice. And helpful to learn shell stuff. Thank you!

            – Olivier Pons
            May 15 '12 at 9:54








          1




          1





          Wow very nice. And helpful to learn shell stuff. Thank you!

          – Olivier Pons
          May 15 '12 at 9:54





          Wow very nice. And helpful to learn shell stuff. Thank you!

          – Olivier Pons
          May 15 '12 at 9:54













          12














          Another possibility to use the ping -D option which gets you the timestamp as Unix time.



          tilo@t-ubuntu:~$ ping google.com -D
          PING google.com (173.194.33.73) 56(84) bytes of data.
          [1388886989.442413] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=1 ttl=57 time=11.1 ms
          [1388886990.443845] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=2 ttl=57 time=11.0 ms
          [1388886991.445200] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=3 ttl=57 time=10.8 ms
          [1388886992.446617] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=4 ttl=57 time=10.9 ms
          ^C
          --- google.com ping statistics ---
          4 packets transmitted, 4 received, 0% packet loss, time 3004ms
          rtt min/avg/max/mdev = 10.860/11.005/11.139/0.123 ms
          tilo@t-ubuntu:~$


          Here a version of "Achu" command with slightly different format:



          ping www.google.com -i 10 -c 3000 | while read pong; do echo "$(date +%Y-%m-%d_%H%M%S): $pong"; done >PingTest_2014-01-04.log


          That gets you:



          2014-01-04_175748: 64 bytes from sea09s16-in-f19.1e100.net (173.194.33.115): icmp_req=13 ttl=57 time=10.5 ms





          share|improve this answer






























            12














            Another possibility to use the ping -D option which gets you the timestamp as Unix time.



            tilo@t-ubuntu:~$ ping google.com -D
            PING google.com (173.194.33.73) 56(84) bytes of data.
            [1388886989.442413] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=1 ttl=57 time=11.1 ms
            [1388886990.443845] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=2 ttl=57 time=11.0 ms
            [1388886991.445200] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=3 ttl=57 time=10.8 ms
            [1388886992.446617] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=4 ttl=57 time=10.9 ms
            ^C
            --- google.com ping statistics ---
            4 packets transmitted, 4 received, 0% packet loss, time 3004ms
            rtt min/avg/max/mdev = 10.860/11.005/11.139/0.123 ms
            tilo@t-ubuntu:~$


            Here a version of "Achu" command with slightly different format:



            ping www.google.com -i 10 -c 3000 | while read pong; do echo "$(date +%Y-%m-%d_%H%M%S): $pong"; done >PingTest_2014-01-04.log


            That gets you:



            2014-01-04_175748: 64 bytes from sea09s16-in-f19.1e100.net (173.194.33.115): icmp_req=13 ttl=57 time=10.5 ms





            share|improve this answer




























              12












              12








              12







              Another possibility to use the ping -D option which gets you the timestamp as Unix time.



              tilo@t-ubuntu:~$ ping google.com -D
              PING google.com (173.194.33.73) 56(84) bytes of data.
              [1388886989.442413] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=1 ttl=57 time=11.1 ms
              [1388886990.443845] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=2 ttl=57 time=11.0 ms
              [1388886991.445200] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=3 ttl=57 time=10.8 ms
              [1388886992.446617] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=4 ttl=57 time=10.9 ms
              ^C
              --- google.com ping statistics ---
              4 packets transmitted, 4 received, 0% packet loss, time 3004ms
              rtt min/avg/max/mdev = 10.860/11.005/11.139/0.123 ms
              tilo@t-ubuntu:~$


              Here a version of "Achu" command with slightly different format:



              ping www.google.com -i 10 -c 3000 | while read pong; do echo "$(date +%Y-%m-%d_%H%M%S): $pong"; done >PingTest_2014-01-04.log


              That gets you:



              2014-01-04_175748: 64 bytes from sea09s16-in-f19.1e100.net (173.194.33.115): icmp_req=13 ttl=57 time=10.5 ms





              share|improve this answer















              Another possibility to use the ping -D option which gets you the timestamp as Unix time.



              tilo@t-ubuntu:~$ ping google.com -D
              PING google.com (173.194.33.73) 56(84) bytes of data.
              [1388886989.442413] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=1 ttl=57 time=11.1 ms
              [1388886990.443845] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=2 ttl=57 time=11.0 ms
              [1388886991.445200] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=3 ttl=57 time=10.8 ms
              [1388886992.446617] 64 bytes from sea09s15-in-f9.1e100.net (173.194.33.73): icmp_req=4 ttl=57 time=10.9 ms
              ^C
              --- google.com ping statistics ---
              4 packets transmitted, 4 received, 0% packet loss, time 3004ms
              rtt min/avg/max/mdev = 10.860/11.005/11.139/0.123 ms
              tilo@t-ubuntu:~$


              Here a version of "Achu" command with slightly different format:



              ping www.google.com -i 10 -c 3000 | while read pong; do echo "$(date +%Y-%m-%d_%H%M%S): $pong"; done >PingTest_2014-01-04.log


              That gets you:



              2014-01-04_175748: 64 bytes from sea09s16-in-f19.1e100.net (173.194.33.115): icmp_req=13 ttl=57 time=10.5 ms






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jan 3 '17 at 15:16









              Eliah Kagan

              82k21227365




              82k21227365










              answered Jan 5 '14 at 2:00









              TiloBuntTiloBunt

              1,28511731




              1,28511731























                  2














                  You can also use gawk (or awk, if your /etc/alternatives/awk points to /usr/bin/gawk):



                  ping -c 4 www.google.fr | gawk '{print strftime("%c: ") $0}'


                  This is similar to the approach in Achu's answer, but ping's output is piped to gawk instead of a shell loop that calls date. As with that approach, it works without -c, but if you don't pass -c n to make ping stop after n pings, and you stop the loop with Ctrl+C, ping won't print the usual statistics.



                  ek@Io:~$ ping -c 4 www.google.fr | gawk '{print strftime("%c: ") $0}'
                  Tue 03 Jan 2017 10:09:51 AM EST: PING www.google.fr (216.58.193.99) 56(84) bytes of data.
                  Tue 03 Jan 2017 10:09:51 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=1 ttl=51 time=327 ms
                  Tue 03 Jan 2017 10:09:52 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=2 ttl=51 time=302 ms
                  Tue 03 Jan 2017 10:09:53 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=3 ttl=51 time=282 ms
                  Tue 03 Jan 2017 10:09:54 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=4 ttl=51 time=349 ms
                  Tue 03 Jan 2017 10:09:54 AM EST:
                  Tue 03 Jan 2017 10:09:54 AM EST: --- www.google.fr ping statistics ---
                  Tue 03 Jan 2017 10:09:54 AM EST: 4 packets transmitted, 4 received, 0% packet loss, time 3003ms
                  Tue 03 Jan 2017 10:09:54 AM EST: rtt min/avg/max/mdev = 282.035/315.227/349.166/25.398 ms


                  ek@Io:~$ ping www.google.fr | gawk '{print strftime("%c: ") $0}'
                  Tue 03 Jan 2017 10:10:35 AM EST: PING www.google.fr (216.58.193.99) 56(84) bytes of data.
                  Tue 03 Jan 2017 10:10:35 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=1 ttl=51 time=305 ms
                  Tue 03 Jan 2017 10:10:35 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=2 ttl=51 time=365 ms
                  Tue 03 Jan 2017 10:10:36 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=3 ttl=51 time=390 ms
                  Tue 03 Jan 2017 10:10:38 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=4 ttl=51 time=824 ms
                  Tue 03 Jan 2017 10:10:38 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=5 ttl=51 time=287 ms
                  ^C


                  This happens whether ping's output is piped to gawk or a shell while loop. The reason is that command on the right side of the pipe, rather than ping, receives SIGINT when Ctrl+C is pressed, and ping does not know to print the statistics before being terminated.



                  If you have run ping without -c on the left side of a pipe (as shown above) and you want to terminate it in such a way that it still prints the statistics, then instead of pressing Ctrl+C in the terminal where it is running, you could run kill -INT PID from another terminal, replacing PID with the process ID of the ping command. If you're only running one instance of ping then you could simply use killall -INT ping.



                  Alternatively, you could replace the ping command on the left side of the pipe with a command that runs a shell, reports the process ID of that shell, and then replaces that shell with the ping command (causing it to have the same PID):



                  sh -c 'echo $$; exec ping www.google.fr' | gawk '{print strftime("%c: ") $0}'


                  Then the first line of output, will show the process ID of the ping command (which will typically be different each time). It would look like this, but with a different time and date and probably a different process ID:



                  Tue 20 Mar 2018 12:11:13 PM EDT: 7557


                  Then, from another terminal, you can run kill -INT 7557, replacing 7557 with the actual process ID you saw, to terminate the ping command in such a way as to cause it to print statistics.



                  (If you take advantage of your shell's job control features, then you can achieve this within the same terminal, too. But if you want to copy text from your terminal without having to remove any extranous part where you ran commands in that terminal, then you should terminate ping from a separate terminal.)



                  Further reading:





                  • Alin's answer to How to derive current date and time and append at the end of each line that contain 'Hello' on Stack Overflow.


                  • 9.1.5 Time Functions in Gawk: Effective AWK Programming (Gawk's official reference manual).


                  • man ping - "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."






                  share|improve this answer


























                  • is there a way to send ctrl+c to ping first?

                    – atti
                    Mar 20 '18 at 12:04






                  • 1





                    @atti Yes, you can send SIGINT (which is what pressing Ctrl+C does) to the ping process specifically, using kill or killall. I've expanded this answer with details.

                    – Eliah Kagan
                    Mar 20 '18 at 17:00
















                  2














                  You can also use gawk (or awk, if your /etc/alternatives/awk points to /usr/bin/gawk):



                  ping -c 4 www.google.fr | gawk '{print strftime("%c: ") $0}'


                  This is similar to the approach in Achu's answer, but ping's output is piped to gawk instead of a shell loop that calls date. As with that approach, it works without -c, but if you don't pass -c n to make ping stop after n pings, and you stop the loop with Ctrl+C, ping won't print the usual statistics.



                  ek@Io:~$ ping -c 4 www.google.fr | gawk '{print strftime("%c: ") $0}'
                  Tue 03 Jan 2017 10:09:51 AM EST: PING www.google.fr (216.58.193.99) 56(84) bytes of data.
                  Tue 03 Jan 2017 10:09:51 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=1 ttl=51 time=327 ms
                  Tue 03 Jan 2017 10:09:52 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=2 ttl=51 time=302 ms
                  Tue 03 Jan 2017 10:09:53 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=3 ttl=51 time=282 ms
                  Tue 03 Jan 2017 10:09:54 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=4 ttl=51 time=349 ms
                  Tue 03 Jan 2017 10:09:54 AM EST:
                  Tue 03 Jan 2017 10:09:54 AM EST: --- www.google.fr ping statistics ---
                  Tue 03 Jan 2017 10:09:54 AM EST: 4 packets transmitted, 4 received, 0% packet loss, time 3003ms
                  Tue 03 Jan 2017 10:09:54 AM EST: rtt min/avg/max/mdev = 282.035/315.227/349.166/25.398 ms


                  ek@Io:~$ ping www.google.fr | gawk '{print strftime("%c: ") $0}'
                  Tue 03 Jan 2017 10:10:35 AM EST: PING www.google.fr (216.58.193.99) 56(84) bytes of data.
                  Tue 03 Jan 2017 10:10:35 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=1 ttl=51 time=305 ms
                  Tue 03 Jan 2017 10:10:35 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=2 ttl=51 time=365 ms
                  Tue 03 Jan 2017 10:10:36 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=3 ttl=51 time=390 ms
                  Tue 03 Jan 2017 10:10:38 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=4 ttl=51 time=824 ms
                  Tue 03 Jan 2017 10:10:38 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=5 ttl=51 time=287 ms
                  ^C


                  This happens whether ping's output is piped to gawk or a shell while loop. The reason is that command on the right side of the pipe, rather than ping, receives SIGINT when Ctrl+C is pressed, and ping does not know to print the statistics before being terminated.



                  If you have run ping without -c on the left side of a pipe (as shown above) and you want to terminate it in such a way that it still prints the statistics, then instead of pressing Ctrl+C in the terminal where it is running, you could run kill -INT PID from another terminal, replacing PID with the process ID of the ping command. If you're only running one instance of ping then you could simply use killall -INT ping.



                  Alternatively, you could replace the ping command on the left side of the pipe with a command that runs a shell, reports the process ID of that shell, and then replaces that shell with the ping command (causing it to have the same PID):



                  sh -c 'echo $$; exec ping www.google.fr' | gawk '{print strftime("%c: ") $0}'


                  Then the first line of output, will show the process ID of the ping command (which will typically be different each time). It would look like this, but with a different time and date and probably a different process ID:



                  Tue 20 Mar 2018 12:11:13 PM EDT: 7557


                  Then, from another terminal, you can run kill -INT 7557, replacing 7557 with the actual process ID you saw, to terminate the ping command in such a way as to cause it to print statistics.



                  (If you take advantage of your shell's job control features, then you can achieve this within the same terminal, too. But if you want to copy text from your terminal without having to remove any extranous part where you ran commands in that terminal, then you should terminate ping from a separate terminal.)



                  Further reading:





                  • Alin's answer to How to derive current date and time and append at the end of each line that contain 'Hello' on Stack Overflow.


                  • 9.1.5 Time Functions in Gawk: Effective AWK Programming (Gawk's official reference manual).


                  • man ping - "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."






                  share|improve this answer


























                  • is there a way to send ctrl+c to ping first?

                    – atti
                    Mar 20 '18 at 12:04






                  • 1





                    @atti Yes, you can send SIGINT (which is what pressing Ctrl+C does) to the ping process specifically, using kill or killall. I've expanded this answer with details.

                    – Eliah Kagan
                    Mar 20 '18 at 17:00














                  2












                  2








                  2







                  You can also use gawk (or awk, if your /etc/alternatives/awk points to /usr/bin/gawk):



                  ping -c 4 www.google.fr | gawk '{print strftime("%c: ") $0}'


                  This is similar to the approach in Achu's answer, but ping's output is piped to gawk instead of a shell loop that calls date. As with that approach, it works without -c, but if you don't pass -c n to make ping stop after n pings, and you stop the loop with Ctrl+C, ping won't print the usual statistics.



                  ek@Io:~$ ping -c 4 www.google.fr | gawk '{print strftime("%c: ") $0}'
                  Tue 03 Jan 2017 10:09:51 AM EST: PING www.google.fr (216.58.193.99) 56(84) bytes of data.
                  Tue 03 Jan 2017 10:09:51 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=1 ttl=51 time=327 ms
                  Tue 03 Jan 2017 10:09:52 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=2 ttl=51 time=302 ms
                  Tue 03 Jan 2017 10:09:53 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=3 ttl=51 time=282 ms
                  Tue 03 Jan 2017 10:09:54 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=4 ttl=51 time=349 ms
                  Tue 03 Jan 2017 10:09:54 AM EST:
                  Tue 03 Jan 2017 10:09:54 AM EST: --- www.google.fr ping statistics ---
                  Tue 03 Jan 2017 10:09:54 AM EST: 4 packets transmitted, 4 received, 0% packet loss, time 3003ms
                  Tue 03 Jan 2017 10:09:54 AM EST: rtt min/avg/max/mdev = 282.035/315.227/349.166/25.398 ms


                  ek@Io:~$ ping www.google.fr | gawk '{print strftime("%c: ") $0}'
                  Tue 03 Jan 2017 10:10:35 AM EST: PING www.google.fr (216.58.193.99) 56(84) bytes of data.
                  Tue 03 Jan 2017 10:10:35 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=1 ttl=51 time=305 ms
                  Tue 03 Jan 2017 10:10:35 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=2 ttl=51 time=365 ms
                  Tue 03 Jan 2017 10:10:36 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=3 ttl=51 time=390 ms
                  Tue 03 Jan 2017 10:10:38 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=4 ttl=51 time=824 ms
                  Tue 03 Jan 2017 10:10:38 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=5 ttl=51 time=287 ms
                  ^C


                  This happens whether ping's output is piped to gawk or a shell while loop. The reason is that command on the right side of the pipe, rather than ping, receives SIGINT when Ctrl+C is pressed, and ping does not know to print the statistics before being terminated.



                  If you have run ping without -c on the left side of a pipe (as shown above) and you want to terminate it in such a way that it still prints the statistics, then instead of pressing Ctrl+C in the terminal where it is running, you could run kill -INT PID from another terminal, replacing PID with the process ID of the ping command. If you're only running one instance of ping then you could simply use killall -INT ping.



                  Alternatively, you could replace the ping command on the left side of the pipe with a command that runs a shell, reports the process ID of that shell, and then replaces that shell with the ping command (causing it to have the same PID):



                  sh -c 'echo $$; exec ping www.google.fr' | gawk '{print strftime("%c: ") $0}'


                  Then the first line of output, will show the process ID of the ping command (which will typically be different each time). It would look like this, but with a different time and date and probably a different process ID:



                  Tue 20 Mar 2018 12:11:13 PM EDT: 7557


                  Then, from another terminal, you can run kill -INT 7557, replacing 7557 with the actual process ID you saw, to terminate the ping command in such a way as to cause it to print statistics.



                  (If you take advantage of your shell's job control features, then you can achieve this within the same terminal, too. But if you want to copy text from your terminal without having to remove any extranous part where you ran commands in that terminal, then you should terminate ping from a separate terminal.)



                  Further reading:





                  • Alin's answer to How to derive current date and time and append at the end of each line that contain 'Hello' on Stack Overflow.


                  • 9.1.5 Time Functions in Gawk: Effective AWK Programming (Gawk's official reference manual).


                  • man ping - "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."






                  share|improve this answer















                  You can also use gawk (or awk, if your /etc/alternatives/awk points to /usr/bin/gawk):



                  ping -c 4 www.google.fr | gawk '{print strftime("%c: ") $0}'


                  This is similar to the approach in Achu's answer, but ping's output is piped to gawk instead of a shell loop that calls date. As with that approach, it works without -c, but if you don't pass -c n to make ping stop after n pings, and you stop the loop with Ctrl+C, ping won't print the usual statistics.



                  ek@Io:~$ ping -c 4 www.google.fr | gawk '{print strftime("%c: ") $0}'
                  Tue 03 Jan 2017 10:09:51 AM EST: PING www.google.fr (216.58.193.99) 56(84) bytes of data.
                  Tue 03 Jan 2017 10:09:51 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=1 ttl=51 time=327 ms
                  Tue 03 Jan 2017 10:09:52 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=2 ttl=51 time=302 ms
                  Tue 03 Jan 2017 10:09:53 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=3 ttl=51 time=282 ms
                  Tue 03 Jan 2017 10:09:54 AM EST: 64 bytes from sea15s08-in-f3.1e100.net (216.58.193.99): icmp_seq=4 ttl=51 time=349 ms
                  Tue 03 Jan 2017 10:09:54 AM EST:
                  Tue 03 Jan 2017 10:09:54 AM EST: --- www.google.fr ping statistics ---
                  Tue 03 Jan 2017 10:09:54 AM EST: 4 packets transmitted, 4 received, 0% packet loss, time 3003ms
                  Tue 03 Jan 2017 10:09:54 AM EST: rtt min/avg/max/mdev = 282.035/315.227/349.166/25.398 ms


                  ek@Io:~$ ping www.google.fr | gawk '{print strftime("%c: ") $0}'
                  Tue 03 Jan 2017 10:10:35 AM EST: PING www.google.fr (216.58.193.99) 56(84) bytes of data.
                  Tue 03 Jan 2017 10:10:35 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=1 ttl=51 time=305 ms
                  Tue 03 Jan 2017 10:10:35 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=2 ttl=51 time=365 ms
                  Tue 03 Jan 2017 10:10:36 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=3 ttl=51 time=390 ms
                  Tue 03 Jan 2017 10:10:38 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=4 ttl=51 time=824 ms
                  Tue 03 Jan 2017 10:10:38 AM EST: 64 bytes from sea15s08-in-f99.1e100.net (216.58.193.99): icmp_seq=5 ttl=51 time=287 ms
                  ^C


                  This happens whether ping's output is piped to gawk or a shell while loop. The reason is that command on the right side of the pipe, rather than ping, receives SIGINT when Ctrl+C is pressed, and ping does not know to print the statistics before being terminated.



                  If you have run ping without -c on the left side of a pipe (as shown above) and you want to terminate it in such a way that it still prints the statistics, then instead of pressing Ctrl+C in the terminal where it is running, you could run kill -INT PID from another terminal, replacing PID with the process ID of the ping command. If you're only running one instance of ping then you could simply use killall -INT ping.



                  Alternatively, you could replace the ping command on the left side of the pipe with a command that runs a shell, reports the process ID of that shell, and then replaces that shell with the ping command (causing it to have the same PID):



                  sh -c 'echo $$; exec ping www.google.fr' | gawk '{print strftime("%c: ") $0}'


                  Then the first line of output, will show the process ID of the ping command (which will typically be different each time). It would look like this, but with a different time and date and probably a different process ID:



                  Tue 20 Mar 2018 12:11:13 PM EDT: 7557


                  Then, from another terminal, you can run kill -INT 7557, replacing 7557 with the actual process ID you saw, to terminate the ping command in such a way as to cause it to print statistics.



                  (If you take advantage of your shell's job control features, then you can achieve this within the same terminal, too. But if you want to copy text from your terminal without having to remove any extranous part where you ran commands in that terminal, then you should terminate ping from a separate terminal.)



                  Further reading:





                  • Alin's answer to How to derive current date and time and append at the end of each line that contain 'Hello' on Stack Overflow.


                  • 9.1.5 Time Functions in Gawk: Effective AWK Programming (Gawk's official reference manual).


                  • man ping - "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."







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 20 '18 at 16:59

























                  answered Jan 3 '17 at 15:15









                  Eliah KaganEliah Kagan

                  82k21227365




                  82k21227365













                  • is there a way to send ctrl+c to ping first?

                    – atti
                    Mar 20 '18 at 12:04






                  • 1





                    @atti Yes, you can send SIGINT (which is what pressing Ctrl+C does) to the ping process specifically, using kill or killall. I've expanded this answer with details.

                    – Eliah Kagan
                    Mar 20 '18 at 17:00



















                  • is there a way to send ctrl+c to ping first?

                    – atti
                    Mar 20 '18 at 12:04






                  • 1





                    @atti Yes, you can send SIGINT (which is what pressing Ctrl+C does) to the ping process specifically, using kill or killall. I've expanded this answer with details.

                    – Eliah Kagan
                    Mar 20 '18 at 17:00

















                  is there a way to send ctrl+c to ping first?

                  – atti
                  Mar 20 '18 at 12:04





                  is there a way to send ctrl+c to ping first?

                  – atti
                  Mar 20 '18 at 12:04




                  1




                  1





                  @atti Yes, you can send SIGINT (which is what pressing Ctrl+C does) to the ping process specifically, using kill or killall. I've expanded this answer with details.

                  – Eliah Kagan
                  Mar 20 '18 at 17:00





                  @atti Yes, you can send SIGINT (which is what pressing Ctrl+C does) to the ping process specifically, using kill or killall. I've expanded this answer with details.

                  – Eliah Kagan
                  Mar 20 '18 at 17:00











                  1














                  There is a utility called 'ts', which reads stdin, adds timestamps, and writes it to stdout:




                  me@my-laptop:~$ ping localhost | ts
                  Nov 08 09:15:41 PING localhost (127.0.0.1) 56(84) bytes of data.
                  Nov 08 09:15:41 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.060 ms
                  Nov 08 09:15:42 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.098 ms
                  Nov 08 09:15:43 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.082 ms
                  Nov 08 09:15:44 64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.091 ms






                  share|improve this answer




























                    1














                    There is a utility called 'ts', which reads stdin, adds timestamps, and writes it to stdout:




                    me@my-laptop:~$ ping localhost | ts
                    Nov 08 09:15:41 PING localhost (127.0.0.1) 56(84) bytes of data.
                    Nov 08 09:15:41 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.060 ms
                    Nov 08 09:15:42 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.098 ms
                    Nov 08 09:15:43 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.082 ms
                    Nov 08 09:15:44 64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.091 ms






                    share|improve this answer


























                      1












                      1








                      1







                      There is a utility called 'ts', which reads stdin, adds timestamps, and writes it to stdout:




                      me@my-laptop:~$ ping localhost | ts
                      Nov 08 09:15:41 PING localhost (127.0.0.1) 56(84) bytes of data.
                      Nov 08 09:15:41 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.060 ms
                      Nov 08 09:15:42 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.098 ms
                      Nov 08 09:15:43 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.082 ms
                      Nov 08 09:15:44 64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.091 ms






                      share|improve this answer













                      There is a utility called 'ts', which reads stdin, adds timestamps, and writes it to stdout:




                      me@my-laptop:~$ ping localhost | ts
                      Nov 08 09:15:41 PING localhost (127.0.0.1) 56(84) bytes of data.
                      Nov 08 09:15:41 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.060 ms
                      Nov 08 09:15:42 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.098 ms
                      Nov 08 09:15:43 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.082 ms
                      Nov 08 09:15:44 64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.091 ms







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 7 '18 at 20:16









                      AMADANON Inc.AMADANON Inc.

                      1907




                      1907























                          0














                          ping google.in | xargs -n1 -i bash -c 'echo `date +"%Y-%m-%d %H:%M:%S"`" {}"'


                          If your interested in saving it in file, then type the below command in the terminal



                          ping google.in | xargs -n1 -i bash -c 'echo `date +"%Y-%m-%d %H:%M:%S"`" {}"' >> "/home/name_of_your_computer/Desktop/Ping_Test.txt"


                          You don't need to create any text files, it'll automatically do



                          Ping_Test.txt



                          2018-04-19 15:35:53 PING google.in (216.58.203.164) 56(84) bytes of data.
                          2018-04-19 15:35:53 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=1 ttl=57 time=23.0 ms
                          2018-04-19 15:35:53 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=2 ttl=57 time=38.8 ms
                          2018-04-19 15:35:54 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=3 ttl=57 time=32.6 ms
                          2018-04-19 15:35:55 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=4 ttl=57 time=22.2 ms
                          2018-04-19 15:35:56 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=5 ttl=57 time=22.1 ms
                          2018-04-19 15:35:59 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=7 ttl=57 time=23.6 ms
                          2018-04-19 15:36:00 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=8 ttl=57 time=22.6 ms
                          2018-04-19 15:36:01 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=9 ttl=57 time=22.3 ms
                          2018-04-19 15:36:02 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=10 ttl=57 time=26.3 ms





                          share|improve this answer




























                            0














                            ping google.in | xargs -n1 -i bash -c 'echo `date +"%Y-%m-%d %H:%M:%S"`" {}"'


                            If your interested in saving it in file, then type the below command in the terminal



                            ping google.in | xargs -n1 -i bash -c 'echo `date +"%Y-%m-%d %H:%M:%S"`" {}"' >> "/home/name_of_your_computer/Desktop/Ping_Test.txt"


                            You don't need to create any text files, it'll automatically do



                            Ping_Test.txt



                            2018-04-19 15:35:53 PING google.in (216.58.203.164) 56(84) bytes of data.
                            2018-04-19 15:35:53 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=1 ttl=57 time=23.0 ms
                            2018-04-19 15:35:53 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=2 ttl=57 time=38.8 ms
                            2018-04-19 15:35:54 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=3 ttl=57 time=32.6 ms
                            2018-04-19 15:35:55 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=4 ttl=57 time=22.2 ms
                            2018-04-19 15:35:56 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=5 ttl=57 time=22.1 ms
                            2018-04-19 15:35:59 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=7 ttl=57 time=23.6 ms
                            2018-04-19 15:36:00 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=8 ttl=57 time=22.6 ms
                            2018-04-19 15:36:01 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=9 ttl=57 time=22.3 ms
                            2018-04-19 15:36:02 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=10 ttl=57 time=26.3 ms





                            share|improve this answer


























                              0












                              0








                              0







                              ping google.in | xargs -n1 -i bash -c 'echo `date +"%Y-%m-%d %H:%M:%S"`" {}"'


                              If your interested in saving it in file, then type the below command in the terminal



                              ping google.in | xargs -n1 -i bash -c 'echo `date +"%Y-%m-%d %H:%M:%S"`" {}"' >> "/home/name_of_your_computer/Desktop/Ping_Test.txt"


                              You don't need to create any text files, it'll automatically do



                              Ping_Test.txt



                              2018-04-19 15:35:53 PING google.in (216.58.203.164) 56(84) bytes of data.
                              2018-04-19 15:35:53 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=1 ttl=57 time=23.0 ms
                              2018-04-19 15:35:53 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=2 ttl=57 time=38.8 ms
                              2018-04-19 15:35:54 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=3 ttl=57 time=32.6 ms
                              2018-04-19 15:35:55 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=4 ttl=57 time=22.2 ms
                              2018-04-19 15:35:56 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=5 ttl=57 time=22.1 ms
                              2018-04-19 15:35:59 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=7 ttl=57 time=23.6 ms
                              2018-04-19 15:36:00 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=8 ttl=57 time=22.6 ms
                              2018-04-19 15:36:01 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=9 ttl=57 time=22.3 ms
                              2018-04-19 15:36:02 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=10 ttl=57 time=26.3 ms





                              share|improve this answer













                              ping google.in | xargs -n1 -i bash -c 'echo `date +"%Y-%m-%d %H:%M:%S"`" {}"'


                              If your interested in saving it in file, then type the below command in the terminal



                              ping google.in | xargs -n1 -i bash -c 'echo `date +"%Y-%m-%d %H:%M:%S"`" {}"' >> "/home/name_of_your_computer/Desktop/Ping_Test.txt"


                              You don't need to create any text files, it'll automatically do



                              Ping_Test.txt



                              2018-04-19 15:35:53 PING google.in (216.58.203.164) 56(84) bytes of data.
                              2018-04-19 15:35:53 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=1 ttl=57 time=23.0 ms
                              2018-04-19 15:35:53 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=2 ttl=57 time=38.8 ms
                              2018-04-19 15:35:54 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=3 ttl=57 time=32.6 ms
                              2018-04-19 15:35:55 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=4 ttl=57 time=22.2 ms
                              2018-04-19 15:35:56 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=5 ttl=57 time=22.1 ms
                              2018-04-19 15:35:59 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=7 ttl=57 time=23.6 ms
                              2018-04-19 15:36:00 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=8 ttl=57 time=22.6 ms
                              2018-04-19 15:36:01 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=9 ttl=57 time=22.3 ms
                              2018-04-19 15:36:02 64 bytes from bom07s11-in-f4.1e100.net (216.58.203.164): icmp_seq=10 ttl=57 time=26.3 ms






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Apr 19 '18 at 10:11









                              Nishanth ॐNishanth ॐ

                              1013




                              1013























                                  -1














                                  (thanks to Achu and Eliah Kagan for the ideas)
                                  there's a way to




                                  • add time to ping output

                                  • keep footnotes of ping

                                  • and terminate this whole construction with ctrl+c


                                  to do this one should instruct right part of the command (after the pipe) to ignore SIGINT using trap "" INT:



                                  $ ping www.google.fr | bash -c 'trap "" INT; awk "{print strftime("%c - ") $0}"'  
                                  lun 26 Mar 2018 22:05:08 +0300 - PING www.google.fr (173.194.73.94) 56(84) bytes of data.
                                  lun 26 Mar 2018 22:05:08 +0300 - 64 bytes from lq-in-f94.1e100.net (173.194.73.94): icmp_seq=1 ttl=47 time=19.6 ms
                                  lun 26 Mar 2018 22:05:09 +0300 - 64 bytes from lq-in-f94.1e100.net (173.194.73.94): icmp_seq=2 ttl=47 time=20.1 ms
                                  ^Clun 26 Mar 2018 22:05:09 +0300 -
                                  lun 26 Mar 2018 22:05:09 +0300 - --- www.google.fr ping statistics ---
                                  lun 26 Mar 2018 22:05:09 +0300 - 2 packets transmitted, 2 received, 0% packet loss, time 1000ms
                                  lun 26 Mar 2018 22:05:09 +0300 - rtt min/avg/max/mdev = 19.619/19.866/20.114/0.284 ms





                                  share|improve this answer






























                                    -1














                                    (thanks to Achu and Eliah Kagan for the ideas)
                                    there's a way to




                                    • add time to ping output

                                    • keep footnotes of ping

                                    • and terminate this whole construction with ctrl+c


                                    to do this one should instruct right part of the command (after the pipe) to ignore SIGINT using trap "" INT:



                                    $ ping www.google.fr | bash -c 'trap "" INT; awk "{print strftime("%c - ") $0}"'  
                                    lun 26 Mar 2018 22:05:08 +0300 - PING www.google.fr (173.194.73.94) 56(84) bytes of data.
                                    lun 26 Mar 2018 22:05:08 +0300 - 64 bytes from lq-in-f94.1e100.net (173.194.73.94): icmp_seq=1 ttl=47 time=19.6 ms
                                    lun 26 Mar 2018 22:05:09 +0300 - 64 bytes from lq-in-f94.1e100.net (173.194.73.94): icmp_seq=2 ttl=47 time=20.1 ms
                                    ^Clun 26 Mar 2018 22:05:09 +0300 -
                                    lun 26 Mar 2018 22:05:09 +0300 - --- www.google.fr ping statistics ---
                                    lun 26 Mar 2018 22:05:09 +0300 - 2 packets transmitted, 2 received, 0% packet loss, time 1000ms
                                    lun 26 Mar 2018 22:05:09 +0300 - rtt min/avg/max/mdev = 19.619/19.866/20.114/0.284 ms





                                    share|improve this answer




























                                      -1












                                      -1








                                      -1







                                      (thanks to Achu and Eliah Kagan for the ideas)
                                      there's a way to




                                      • add time to ping output

                                      • keep footnotes of ping

                                      • and terminate this whole construction with ctrl+c


                                      to do this one should instruct right part of the command (after the pipe) to ignore SIGINT using trap "" INT:



                                      $ ping www.google.fr | bash -c 'trap "" INT; awk "{print strftime("%c - ") $0}"'  
                                      lun 26 Mar 2018 22:05:08 +0300 - PING www.google.fr (173.194.73.94) 56(84) bytes of data.
                                      lun 26 Mar 2018 22:05:08 +0300 - 64 bytes from lq-in-f94.1e100.net (173.194.73.94): icmp_seq=1 ttl=47 time=19.6 ms
                                      lun 26 Mar 2018 22:05:09 +0300 - 64 bytes from lq-in-f94.1e100.net (173.194.73.94): icmp_seq=2 ttl=47 time=20.1 ms
                                      ^Clun 26 Mar 2018 22:05:09 +0300 -
                                      lun 26 Mar 2018 22:05:09 +0300 - --- www.google.fr ping statistics ---
                                      lun 26 Mar 2018 22:05:09 +0300 - 2 packets transmitted, 2 received, 0% packet loss, time 1000ms
                                      lun 26 Mar 2018 22:05:09 +0300 - rtt min/avg/max/mdev = 19.619/19.866/20.114/0.284 ms





                                      share|improve this answer















                                      (thanks to Achu and Eliah Kagan for the ideas)
                                      there's a way to




                                      • add time to ping output

                                      • keep footnotes of ping

                                      • and terminate this whole construction with ctrl+c


                                      to do this one should instruct right part of the command (after the pipe) to ignore SIGINT using trap "" INT:



                                      $ ping www.google.fr | bash -c 'trap "" INT; awk "{print strftime("%c - ") $0}"'  
                                      lun 26 Mar 2018 22:05:08 +0300 - PING www.google.fr (173.194.73.94) 56(84) bytes of data.
                                      lun 26 Mar 2018 22:05:08 +0300 - 64 bytes from lq-in-f94.1e100.net (173.194.73.94): icmp_seq=1 ttl=47 time=19.6 ms
                                      lun 26 Mar 2018 22:05:09 +0300 - 64 bytes from lq-in-f94.1e100.net (173.194.73.94): icmp_seq=2 ttl=47 time=20.1 ms
                                      ^Clun 26 Mar 2018 22:05:09 +0300 -
                                      lun 26 Mar 2018 22:05:09 +0300 - --- www.google.fr ping statistics ---
                                      lun 26 Mar 2018 22:05:09 +0300 - 2 packets transmitted, 2 received, 0% packet loss, time 1000ms
                                      lun 26 Mar 2018 22:05:09 +0300 - rtt min/avg/max/mdev = 19.619/19.866/20.114/0.284 ms






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Mar 26 '18 at 22:49









                                      muru

                                      1




                                      1










                                      answered Mar 26 '18 at 19:23









                                      attiatti

                                      1393




                                      1393






























                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Ask Ubuntu!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f137233%2fhow-to-command-ping-display-time-and-date-of-ping%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Human spaceflight

                                          Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

                                          File:DeusFollowingSea.jpg