Search code examples
linuxbashtimesynchronizentp

Print time from external server in bash


I'd like to know if it's possible to simply retrieve a Unix timestamp from an external server (using NTP, I suppose). I know there's ntpd, which will update the current system time to the time given by an NTP server, but I only want to read the timestamp. Is it possible using a Bash command in Linux? If not, I guess I'll just have to write a Python (or something) app to get it and print it on the shell.


Solution

  • Some servers provide the daytime daemon which can give you what you want, in textual form anyway.

    Try:

    telnet SERVER daytime
    

    on your favorite SERVER.

    Example transcript:

    pax$ telnet time.nist.gov daytime
    Trying 192.43.244.18...
    Connected to time.nist.gov.
    Escape character is '^]'.
    
    55860 11-10-26 06:33:38 12 0 0 438.2 UTC(NIST) *
    Connection closed by foreign host.