[ntp:questions] Reference Clock driver for getting time via "date" command over telnet?

Rob nomail at example.com
Wed Apr 21 16:35:07 UTC 2010


Movis <ben at internetaddress.com> wrote:
> Hello,
>
> For reasons outside my control, I wish to configure ntpd on Red Hat to
> use as the refclock a time obtained by repeatedly telnetting to a
> remote machine and using the "date" command.
>
> In other words, I will have a string from a script which would then be
> given to my local ntp server as the reference clock. I do not have the
> option of opening a port forwarding tunnel or vpn over which to use
> ntp between these two servers.

What you need to do is write a program that opens a shared memory segment
where it stores the data you get via the "date" command, and configure
ntpd to use shared memory like this:

server 127.127.28.0

Driver 28 will read the shared memory where the time info is stored by
the special program.

The shared memory is layed out like this:

struct shmTime {
    int    mode; /* 0 - if valid set
                  *       use values,
                  *       clear valid
                  * 1 - if valid set
                  *       if count before and after read of values is equal,
                  *         use values
                  *       clear valid
                  */
    int    count;
    time_t clockTimeStampSec;
    int    clockTimeStampUSec;
    time_t receiveTimeStampSec;
    int    receiveTimeStampUSec;
    int    leap;
    int    precision;
    int    nsamples;
    int    valid;
    int    pad[10];
};

There is documentation about how to use it in the ntpd documents.


Of course you need a modern "date" command to get any useful info.
Try if it supports the following syntax:

date +%s.%N

This should return a fractional number of seconds since 1970.
This is much easier to parse into the shared memory structure shown
above, and if you only can get integer seconds from the "date" command
it will not be good enough to obtain ntpd lock from it.




More information about the questions mailing list