ntpdate gets the time and date right on your Puppy

Configuration wizards, scanners, remote desktop, etc.
Post Reply
Message
Author
musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

ntpdate gets the time and date right on your Puppy

#1 Post by musher0 »

Hello all.

I've always had a problem with Puppy setting the date and time correctly
for my session. I was setting my time zone correctly, but no luck.

Except with psync, but some Puppies don't have it. And more often than
not, psync is a slowpoke, IMO.

I started searching for an alternative.

At ntp.org, you'll find material to set up your own ntp server if you like,
but there you'll also find a small utility called ntpdate which does exactly
this: set the time on your computer against the data provided by an ntp
server in your country.

~~~~~~~~~

Note --
ntpdate needs the libssl.so.1.1 and libcrypto.so.1.1 to work. Some Pups,
like petihar's Tahr derivative, Triton, do not have it. The following
pinstall.sh script will correct that situation.

Please read the comments in the code below so you won't fall
off your chair
if the libs start downloading.

It will also set the country properly in the /etc/ntp.conf file.

Code: Select all

#!/bin/sh
# pinastall.sh # for ntpdate pet
# What this script does:
# 1) It checks if you have the proper ssl and crypto libraries for ntpdate;
# 2) It sets the ntp server configuration file for your country.
# (c) musher0, Aug. 7 2017. GPL3. Please read:
# https://opensource.org/licenses/GPL-3.0
####
A=/usr/lib/libssl.so.1.1;B=/usr/lib/libcrypto.so.1.1
if [ "`ls $A`" != "$A" -o "`ls $B`" != "$B" ];then
# This part gets and installs the libs if not installed in your Puppy. 
	cd ~/my-applications
	wget http://dl.fedoraproject.org/pub/fedora-secondary/releases/26/Everything/i386/os/Packages/o/openssl-libs-1.1.0f-4.fc26.i686.rpm
# This takes a few seconds.
	petget openssl-libs-1.1.0f-4.fc26.i686.rpm
# You may wish to delete this rpm archive when done. 
# (This openssl archive also contains the libcrypto library.)
fi
##
CountrY="${LANG:3:2}";CountrY="${CountrY,,}"
if [ "`grep -v $CountrY /etc/ntp.conf`" ];then
# If you are in Canada, you don't need this part, because the default
configuration file already points to Canadian servers.
	echo "server 0.$CountrY.pool.ntp.org
server 1.$CountrY.pool.ntp.org
server 2.$CountrY.pool.ntp.org
server 3.$CountrY.pool.ntp.org" > /etc/ntp.conf
fi
## Fin | End ##
This script fetches the dependencies if you don't have them on your Puppy,
and sets the country code for ntpdate according to the second part of your
LANG variable.

The LANG variable syntax is always the pair "language-country" (plus the
utf8 at the end). For ex.: en_US, en_AU, fr_CA, pt_BR. It was easy enough
to extract it for re-use in the ntp.conf file.

I haven't thoroughly checked, but I believe only the smallest countries do
not have their own time server(s). If you live in a country which does not
have a time server, please let me know your country code and I'll try to
incorporate it in the pinstall script. TIA.

At the opposite end, if you live in a large country such as the US, Australia
or Canada, it is not necessary to specify the state or province nearest you:
the ntpdate utility will figure it out through its other configuration file,
ntp.drift, located at /var/lib/ntp. With this, ntpdate can use the ntp server
nearest you, and set your computer date and time faster.

Ntpdate works this way:
based on the country information provided in /etc/ntp.conf, it connects to
the nearest server available in the ntp pool of servers for your country.
(Some countries have dozens, even hundreds, of ntp servers.)

~~~~~~~~~

An advantage of ntpdate is that it will correctly set the date and time on
your computer even if your computer battery is dead! There you go:
musher0 just saved you five bucks! :)

~~~~~~~~~

Once this pet is installed, please have a look at ~/Startup. You'll see the
ntpdate launcher there is named "zz-ntp-sync.sh". That's on purpose.

This script needs to be the last one called in the Startup chain. I found that
out through experience, I'm not an ntp specialist. Please do not rename
this Startup script.

My tentative explanation is that an ntp connection needs a bit of time to
establish itself properly, and launchers running afterwards would disturb it.

If someone could fill us in with some science on that, it would be great.

~~~~~~~~~

I've been using ntpdate on various recent Puppies (Tahr, Puduan, Slim6,
DPupStretch) for about six months now, and I never had a problem with it.

Your constructive and improvement-oriented feedback is always welcome.

BFN.
Attachments
ntp-4.2.8p10_simple.pet
(65.14 KiB) Downloaded 238 times
Last edited by musher0 on Sun 20 Aug 2017, 21:04, edited 1 time in total.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

Re: ntpdate gets the time and date right on your Puppy

#2 Post by Moose On The Loose »

musher0 wrote:Hello all.

I've always had a problem with Puppy setting the date and time correctly
for my session. I was setting my time zone correctly, but no luck.

Except with psync, but some Puppies don't have it. And more often than
not, psync is a slowpoke, IMO.
Attached is my variation on psync for 528.
The intended changes were:
--The dialog box fits onto the screen on a 640x400
--When it has troubles it trys to explain what went wrong.

I have been using it for a long time now and it has never seemed slow to me. Some of what it does maybe could be combined with your ntpdate.
Attachments
psync-2.0.pet
(5.65 KiB) Downloaded 231 times

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#3 Post by musher0 »

I'll have a look at it. Thanks, Moose.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#4 Post by musher0 »

Hello all.

After a few tests, this is the wrapper that I now use in /root/Startup:

Code: Select all

#!/bin/sh
# ~/Startup/zz-ntp-sync.sh
#
# So named because this script should be the last to be launched in the ~/Startup directory.
#
# Goal: Adjust the time on your computer clock by synchronizing it with an ntp server.
#
# Requires the ntp suite. (De : / From: http://www.ntp.org/downloads.html)
# Also the configuration files: /etc/ntp.conf, /var/lib/ntp/ntp.drift.
#
# Source : http://www.pool.ntp.org/fr/use.html
#
# (c) Christian L'Écuyer, Gatineau (Qc), Canada, 3 avril 2017. GPL3
# (Alias musher0 [forum Puppy].) # https://opensource.org/licenses/GPL-3.0
# Rév. : 16 juin, 3 juillet et 13 août 2017.
#
#### 
[ "`lsof -i | grep -o dhcpcd`" ] || sleep 15s 
# Wait until frisbee has established a connection. 
# The real lsof is needed here, not the busybox contraption of lsof.

ntpdate pool.ntp.org
YMMV. BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#5 Post by musher0 »

Hello all.

I've been reading a bit on dhcpcd. I found that the lsof line above can be
successfully replaced by

Code: Select all

[ "`ps | awk '$4 ~ /dhcpcd/'`" ] || sleep 15s
This entirely removes the need to call any type of lsof to check.

We query with < ps > if dhcpcd is running in memory. If it is, we proceed
without pause to retrieving or validating our computer's time data. This is
useful when recycling our sessions during the day.

On the other hand, the 15 seconds wait is useful on the 1st boot of the
day. On 1st boot, we indeed have to wait until freesbee or another "Puppy
connector" establishes the connection.

After some tests, I discovered that 15 seconds is the best delay on this
machine, but don't hesitate to increase this number if your connection
needs more time to get established.

~~~~~~~~~~~~~~~~

Finally, please note that I cannot test a wi-fi connection, since AFAIK, we
only have ethernet connection in this neighborhood. It would be great if
one of you could complement this little script with a check for a wi-fi
connection, for those who do not have cable Internet.

I understand that freesbee is supposed to take care of wi-fi as well as
ethernet connections, so if the script doesn't need a complement for wi-fi,
I'd appreciate your letting me know as well.

TIA.


~~~~~~~~~~~~~~~~

IHTH. BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

#6 Post by Moose On The Loose »

musher0 wrote:Hello all.
And a gracious good morning to you.

It seems to me that checking that the internet is functioning is complicated unless you consider the ability to reach a specific site as the indication.

Code: Select all


if ping -c 1 www.bogus.com ; then echo "Internet connected"; fi
ping: bad address 'www.bogus.com'

if ping -c 1 www.duckduckgo.com ; then echo "Internet connected"; fi
PING www.duckduckgo.com (50.18.192.250): 56 data bytes
64 bytes from 50.18.192.250: seq=0 ttl=51 time=12.831 ms

--- www.duckduckgo.com ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 12.831/12.831/12.831 ms
Internet connected

[/quote]

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#7 Post by musher0 »

HI Moose.

Thanks for the reminder.
But the script above is working, so I'm not fixing it! ;)

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Post Reply