Tiny Core Base > TCB Tips & Tricks

[trick] get the time for your clock

<< < (2/6) > >>

ferran:
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: ---#!/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

--- End code ---

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: ---#!/bin/busybox ash
# bmarkus - 26/02/2014

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

--- End code ---

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


--- Code: ---pool.ntp.org

--- End code ---

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


--- Code: ---server 0.es.pool.ntp.org
server 1.es.pool.ntp.org
server 2.es.pool.ntp.org
server 3.es.pool.ntp.org

--- End code ---

I don't know If now works (because my clock was changed before). Surely yes... Tomorrow we'll know it :)

jazzbiker:
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: ---server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org

--- End code ---

as ntp.org recommend. And then call


--- Code: ---sudo ntpd -q

--- End code ---

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: ---sudo getTime.sh
echo $?
date

--- End code ---

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.

ferran:
Ok, ok. Let me restore the files changed before like the original and after i will do you said.

jazzbiker:
By the way, if You are sure that Your RTC is dead You can use NORTC boot code.

ferran:
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.



Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version