WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [trick] get the time for your clock  (Read 10895 times)

Offline ferran

  • Full Member
  • ***
  • Posts: 159
[trick] get the time for your clock
« on: March 23, 2020, 06:18:45 AM »
Hello / Hi everybody:

If your TC clock is broken usually because the hardware clock's battery is dead (like to me), I suggest you to use this command

ntpd -q -p (here the pool.ntp.org server)

NOTE: You must be connected to internet

Before let's take a look to ntp servers in its web:

https://support.ntp.org/bin/view/Servers/NTPPoolServers

Search the most fine hostname time zone browsing first by continent and after by your nation state or country. In my case i found 0.es.pool.ntp.org, so

Code: [Select]
ntpd -q -p 0.es.pool.ntp.org

Suddenly my desktop clock changed the time!. I hope it works to you as fine as to me.
« Last Edit: March 23, 2020, 06:27:16 AM by ferran »
TC CorePlus v.11.1 i686 & lots of coffe

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: [trick] get the time for your clock
« Reply #1 on: March 23, 2020, 06:34:53 AM »
Hi, ferran!

Great trick! The right time for the running system is one of the cornerstones. Not trying to underscore Your efforts I propose to look at /usr/bin/getTime.sh script. In general there are a lot of interesting things inside TinyCore. And there is wiki on the project site, worth digging into.

Regards!

Offline ferran

  • Full Member
  • ***
  • Posts: 159
Re: [trick] get the time for your clock
« Reply #2 on: March 23, 2020, 06:55:21 AM »
Thanks!  :)

I saw this script but not works to me (surely because it imports from /etc/sysconfig/ntpserver the generic server "pool.ntp.org". It lefts to be more specific with the time-zone)
TC CorePlus v.11.1 i686 & lots of coffe

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: [trick] get the time for your clock
« Reply #3 on: March 23, 2020, 08:15:37 AM »
Hi, ferran!

Interesting that ntpd doesn't work for You with pool.ntp.org. They must find appropriate local time server with the help of DNS. Such fail means, that for some reason they can't find You correctly. Does getTime.sh fails always, or sometimes it sets the time? Maybe try to play with /etc/ntpd.conf? I mean the proposed content
Code: [Select]
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org

I never had problems with time setting, so I can not check this issue and help You with testing. Probably to emulate such problems i will need to brake my DNS.

Offline ferran

  • Full Member
  • ***
  • Posts: 159
Re: [trick] get the time for your clock
« Reply #4 on: March 23, 2020, 08:47:57 AM »
Very good !. In this moments i can't to test it, but i will tell you something very soon.

TC CorePlus v.11.1 i686 & lots of coffe

Offline ferran

  • Full Member
  • ***
  • Posts: 159
Re: [trick] get the time for your clock
« Reply #5 on: March 23, 2020, 01:48:24 PM »
jazzbiker:

Well, in my TC CorePlus 11.0 version I haven't /etc/ntpd.conf, I've /etc/sysconfig/ntpserver.

All this theme is a bit more difficult it seems (for me) and for this reason I decided to change the time directly with a single command.

Robert Shingledecker first and Bela Marcus after made the /etc/init.d/settime.sh:

Code: [Select]
#!/bin/sh
# (c) Robert Shingledecker 2012
#     Bela Markus 2015

# Wait for network to come up and then set time

CNT=0
until ifconfig | grep -q Bcast
do
    [ $((CNT++)) -gt 60 ] && break || sleep 1
done

if [ $CNT -le 60 ]
then
    CNT=9999
    NRT=0
    while sleep 0
    do
        XXX=$(/bin/date -I)
        XXX=${XXX:0:4}

        if [ "$XXX" -ge "2015" ];
        then
            break
        fi

        if [ $CNT -gt 10 ];
        then
            /usr/bin/getTime.sh
            if [ $NRT -gt 5 ];
            then
                break
            fi
            CNT=0
            NRT=$((NRT+1))
        fi

    CNT=$((CNT+1))
    sleep 1
    done
fi

I changed the line if [ "$XXX" -ge "2015" ]; with  if [ "$XXX" -ge "2021" ];


Now looks that it forks to another script named /usr/bin/getTime.sh . With the above correction If the year is less than "2021" the script forks to the getTime.sh (made by Bela Markus too) is:

Code: [Select]
#!/bin/busybox ash
# bmarkus - 26/02/2014

NTPSERVER=$(cat /etc/sysconfig/ntpserver)
/usr/sbin/ntpd -q -p $NTPSERVER

Finally It forks (again) to an another script named /etc/sysconfig/ntpserver which It contents only this:

Code: [Select]
pool.ntp.org

I changed with your suggestion (but for Spain) with:

Code: [Select]
server 0.es.pool.ntp.org
server 1.es.pool.ntp.org
server 2.es.pool.ntp.org
server 3.es.pool.ntp.org

I don't know If now works (because my clock was changed before). Surely yes... Tomorrow we'll know it :)
« Last Edit: March 23, 2020, 01:56:46 PM by ferran »
TC CorePlus v.11.1 i686 & lots of coffe

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: [trick] get the time for your clock
« Reply #6 on: March 23, 2020, 02:17:26 PM »
Hi, ferran!

I think You don't need to change settime.sh. This part of it comparing year with 2015 is only for early Raspberries, which had no RTC at all, as far as i know. So leave settime.sh unchanged.

Now about /etc/ntp.conf and /etc/sysconfig/ntpserver. Really, TinyCore have no /etc/ntp.conf. The only ntp server name is stored in /etc/sysconfig/ntpserver text file and is used by getTime.sh script. But in order to make various servers acceptable by ntpd I proposed to create /etc/ntp.conf and write into it
Code: [Select]
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org

as ntp.org recommend. And then call

Code: [Select]
sudo ntpd -q

without naming certain server with the help of -p switch and allow ntpd to choose server from /etc/ntp.conf

Maybe other TinyCore users face the same problems with time determining? If You will find the way to solve problem not only for Spain it can be usefull for others too.

I still don't understand why ntp.org can not locate You on our planet correctly. That is why i proposed to continue experiments with original getTime.sh ( before creating /etc/ntp.conf ).

For example: You boot Your box and have wrong time on it. The You bring up the network and
Code: [Select]
sudo getTime.sh
echo $?
date

maybe several times until time will be set correct. It seems to me that getTime.sh can not fail absolutely, because pool.ntp.org is choosing various ntp servers for every new call.

Offline ferran

  • Full Member
  • ***
  • Posts: 159
Re: [trick] get the time for your clock
« Reply #7 on: March 23, 2020, 02:54:15 PM »
Ok, ok. Let me restore the files changed before like the original and after i will do you said.
TC CorePlus v.11.1 i686 & lots of coffe

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: [trick] get the time for your clock
« Reply #8 on: March 23, 2020, 02:59:55 PM »
By the way, if You are sure that Your RTC is dead You can use NORTC boot code.

Offline ferran

  • Full Member
  • ***
  • Posts: 159
Re: [trick] get the time for your clock
« Reply #9 on: March 23, 2020, 03:29:15 PM »
Here I returned.

So I made the /etc/conf as you said. Also i wrote sudo ntpd -q, sudo getTime.sh and the echo says "0". Obviously the date its the same (I changed it when i connected before).

I don't understand why don't works too... luckily i'll have time to find out.

About NORTC i don't know what i must to do yet. I'll look into it further.



TC CorePlus v.11.1 i686 & lots of coffe

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: [trick] get the time for your clock
« Reply #10 on: March 23, 2020, 03:55:24 PM »
Hi, ferran!

What is /etc/conf? ntpd is looking for /etc/ntp.conf
You can read about boot codes in wiki or in FAQ.
I don't understand what's going on, and I can not do any testing, so let's take the things as they are. You have the working ntp servers, so anybody can repeat Your steps, if necessary.

Offline ferran

  • Full Member
  • ***
  • Posts: 159
Re: [trick] get the time for your clock
« Reply #11 on: March 23, 2020, 04:20:54 PM »
Hi, ferran!

What is /etc/conf? ntpd is looking for /etc/ntp.conf
You can read about boot codes in wiki or in FAQ.
I don't understand what's going on, and I can not do any testing, so let's take the things as they are. You have the working ntp servers, so anybody can repeat Your steps, if necessary.

yes. I would say /etc/ntp.conf It was just a writing mistake.

Ok. It's a good moment that the people talks :)
TC CorePlus v.11.1 i686 & lots of coffe

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: [trick] get the time for your clock
« Reply #12 on: March 23, 2020, 05:56:55 PM »
Hi, ferran!

Some observations about ntpd.
Exit code with -q switch says nothing about sucess or fail:
Code: [Select]
tc@box:~$ sudo ntpd  -q -p rubbish.box
tc@box:~$ echo $?
0

Some peer acessibility testing may be done with the help of -w switch:

Code: [Select]
tc@box:~$ sudo ntpd -w -p pool.ntp.org
ntpd: reply from 91.236.251.29: offset:+0.012651 delay:0.031612 status:0x24 strat:2 refid:0x15119582 rootdelay:0.026810 reach:0x01
ntpd: reply from 91.236.251.29: offset:+0.020740 delay:0.017485 status:0x24 strat:2 refid:0x15119582 rootdelay:0.026810 reach:0x03
^C

Code: [Select]
tc@box:~$ sudo ntpd -w -p 0.es.pool.ntp.org
ntpd: reply from 81.19.96.148: offset:+0.029865 delay:0.085033 status:0x24 strat:2 refid:0x4dcccb8c rootdelay:0.035935 reach:0x01
ntpd: reply from 81.19.96.148: offset:+0.030063 delay:0.087207 status:0x24 strat:2 refid:0x4dcccb8c rootdelay:0.035935 reach:0x03
^C

Code: [Select]
tc@box:~$ sudo ntpd  -w -p rubbish.box
ntpd: bad address 'rubbish.box'
ntpd: bad address 'rubbish.box'
^C

Multiple servers can be used:
Code: [Select]
tc@box:~$ sudo ntpd  -w -p rubbish.box -p pool.ntp.org
ntpd: bad address 'rubbish.box'
ntpd: reply from 79.142.192.130: offset:+0.019904 delay:0.002564 status:0x24 strat:3 refid:0x963937f8 rootdelay:0.009308 reach:0x01
ntpd: bad address 'rubbish.box'
ntpd: reply from 79.142.192.130: offset:+0.019750 delay:0.002560 status:0x24 strat:3 refid:0x963937f8 rootdelay:0.009308 reach:0x03
ntpd: reply from 79.142.192.130: offset:+0.019888 delay:0.002740 status:0x24 strat:3 refid:0x963937f8 rootdelay:0.009308 reach:0x07
^C

If You will be in the mood for experimenting, it will be interesting to see the results.


Offline ferran

  • Full Member
  • ***
  • Posts: 159
Re: [trick] get the time for your clock
« Reply #13 on: March 23, 2020, 07:57:50 PM »
Yes. the last discovery i did was to aply the /etc/ntp.conf into the ntpd -w -q

Code: [Select]
sudo ntpd -w -q /etc/ntp.conf

It works successfully ! but the /etc/ntp.conf dissapear with each reboot or shutdown  :'(

TC CorePlus v.11.1 i686 & lots of coffe

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11617
Re: [trick] get the time for your clock
« Reply #14 on: March 23, 2020, 08:05:37 PM »
Hi ferran
You need to add:
Code: [Select]
etc/ntp.confto your  /opt/.filetool.lst  file and then run a backup. Note there is no leading slash in the path.