Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 23 Oct 2019, 22:28
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
How to set time
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 2 of 2 [25 Posts]   Goto page: Previous 1, 2
Author Message
musher0

Joined: 04 Jan 2009
Posts: 14414
Location: Gatineau (Qc), Canada

PostPosted: Thu 27 Dec 2018, 03:16    Post subject:  

Hello all.

Please find attached as a pet the htpdate utility compiled for the most
recent slacko-700 and ScPup-19.01
(at the time of this writing).

It may or may not be suited for other Pups, since this exec requires
GNU libc version 2.28 to work. Please check the ldd version in your Pup,
like so: open a console and type in it:
Code:
ldd --version
It will tell you.

I tested it thoroughly (I think), but use at your own peril, as usual.
Please take a minute to read the NOTE in the script below and call the
htpdate man page if you need more info. Or leave your question below.

Enjoy.

~~~~~~~~~~~~
Code:
#!/bin/bash
MBINS=/root/my-applications/bin
[ ! -d $MBINS ] && MBINS=/opt/local/bin
# $MBINS/htpdate.sh
# With link in: / Avec lien dans : /root/Startup
#
# Goal: Synchronise the time and date of your Puppy with Internet
# ----- time by probing various http sites.
#
# Objectif : Synchroniser le temps et l'heure de votre Toutou ou
# ---------- Puppy en sondant divers sites http.
#
# Please read the NOTE below. / S.v.p. lire la NOTE ci-dessous.
#
# (c) musher0, Gatineau (Qc), Canada, 27 décembre 2018. GPL3.
####
[ -f /root/root/last-date ] && date --set="`cat /root/last-date`" || date --set="20181227 14:28"
sleep 2s

htpdate -as www.linux.org www.freebsd.org www.ask.com unix.stackexchange.com puppylinux.com www.gnu.org www.cnrs.fr www.assnat.qc.ca www.parl.ca

date > /root/last-date

exit

~~~~~~~~~~~~~~
~~ NOTE ~~
~~~~~~~~~~~
Replaces /usr/local/ptimesync and /root/Startup/timesync.sh
(please remove or store out of the way) in slacko-700_32-bits.

As it is, this script should offer a precision between 0.6 and
0.167 of a second.

If you wish, you can test and use other public sites than
those above.

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

Remplace /usr/local/ptimesync et /root/Startup/timesync.sh
(s.v.p. enlever ou entreproser ailleurs) dans slacko-700_32-bits.

Tel quel, le script devrait offrir une précision de 0,6 à 0,167
seconde.

Si vous le souhaitez, vous pouvez tester et utiliser d'autres
sites publics que ceux ci-dessus.
~~~~~~~~~~~~~~


In the picture below
-- the first line is the command itself;
-- the second line is the date and time in file "last-date";
-- the third line is the update from "last-date";
-- the fourth line is the new current time and date.

AFAICT, htpdate gives an error if you start it on a computer with a dead
battery. Please correct me if I'm wrong, but htpdate does not seem to be
able to recognize old dates such as "Jan. 3 1980, 00:01 hr".

As a workaround, I devised the following:
The fictitious relatively recent date contained in file "last-date" is fed into
the OS by command < date --set="`cat /root/last-date`" >. If file
"last-date" does not exist it is created. Then htpdate updates from that
time and date. That way, it's easier on the girl! Wink

IHTH.
Running-htpdate.sh.jpg
 Description   Running htpdate.sh in console will give you something like this.
 Filesize   18.23 KB
 Viewed   501 Time(s)

Running-htpdate.sh.jpg

htpdate-master-181227.pet
Description 
pet

 Download 
Filename  htpdate-master-181227.pet 
Filesize  10.02 KB 
Downloaded  220 Time(s) 

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14414
Location: Gatineau (Qc), Canada

PostPosted: Fri 28 Dec 2018, 22:07    Post subject:  

Hello all.

Please find attached an update.

Useful info, I think, from the newly edited script.
Quote:
# Required: htpdate (in the pet archive containing this script)
# --------- hwclock, grep (already in your Pup).
(...)
# The hwclock "check and set" at lines 17 and 28 was needed
# to allow setting the time for the user's entire session.
(...)

# As it is, this script should offer a precision between 0.6 and
# 0.167 of a second.

# I am using the sites of the Parliament of Canada and of Québec's
# National Assembly among other time servers. If checking those sites
# takes too much time because they are too far away, please feel free to
# test and incorporate in the htpdate URL series above other public or
# governmental sites closer to your location.

# This script should prove useful if your computer battery is dead.

The major change in this version is the use of hwclock to introduce some
permanence of the time data at the HW level for your entire session. This
means that htpdate works only once, at the beginning of your session.

Should you change WM's, say, during your session, or temporarily go to the
initial black console to check something, and then come back in X, the time
data will have been preserved. The time in your task bar or in your analog
clock if you have one, should follow the natural increment for the duration.

When you relaunch a session the next day, later in the day, or some other
day, the script will find a mini file with the previous day's time data in it, so
htpdate does not have to figure out the present time starting from zilch. At
boot, a discrepancy will show in your computer clocks, but it will correct
itself automatically after approx. a minute. During the rest of your session,
this script should now offer "smooth sailing".

If the above is not clear, please leave your question below. Comments and
try-out reports also welcome.

Enjoy.
htpdate-0.2.pet
Description 
pet

 Download 
Filename  htpdate-0.2.pet 
Filesize  12.65 KB 
Downloaded  198 Time(s) 

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14414
Location: Gatineau (Qc), Canada

PostPosted: Sat 29 Dec 2018, 02:41    Post subject:  

Hello again, all.

I continued testing with htpdate, and this version of the script seems
to work the best. Please ditch any previous version.

I moved the script to /etc/init.d, under the filename start_
htpdate-0.3.sh and removed the symlink in /root/Startup.

Scripts in /etc/init.d with the 'start' prefix are run before the ones in
/root/Startup. This gives the script more time to establish the system
time and date, with the added benefit that there is less of a bottleneck
in /root/Startup at boot time.

I reworded the NOTE to include a solution if the script seems to jam
after a power outage or something as drastic.
Please make a mental
note. It is:
Quote:
# IMPORTANT: After a power outage or any sudden break of the OS,
# this script may fail. To restore normal operation, open a console in
# /root/my-applications/bin and type, exactly:
# `grep htpdate htpdate-0.3.sh | grep -v "#"`
# rerun this script and then reboot.

Unless i get some problematic feedback for you guys, I think this will be
the last version.

Enjoy.
htpdate-0.3a.pet
Description  This is potentially the last version, so please remove any previous one.
pet

 Download 
Filename  htpdate-0.3a.pet 
Filesize  15.44 KB 
Downloaded  200 Time(s) 

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
gychang


Joined: 29 Nov 2008
Posts: 303
Location: San Diego, CA

PostPosted: Sun 24 Feb 2019, 14:49    Post subject: Re: How to set time
Subject description: Trinitydog and Stretchdog
 

labbe5 wrote:
In Trinitydog :

First, i installed ntp.
Then i added ca.pool.ntp.org in /etc/systemd/timesyncd.conf.

The file looks like this :

[Time]
NTP=ca.pool.ntp.org #nearest server for me

Testing in terminal :
timedatectl status

Resulting values :
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no

Finally, reboot.
Now time should be correct.

In Stretchdog with Openbox (from mklive-stretch script & default config)

An alternative way of setting system time.

UTC is used, and there is a mismatch between UTC and local time.

To set the time :
# date -s hh:mm:ss #in Conky, UTC is now set to local time
To set the hardware clock :
# hwclock --systohc --utc

Now local time is ok and is set persistently.

Website of interest related to time zones : http://www.timebie.com/std/edt.php?q=15.5

Further reading :
http://www.putorius.net/2015/04/setting-time-and-date-in-red-hat-7.html


If you are getting wrong time with the USA pacific zone, make sure on initial quick setup screen set "America_Los_Angeles" NOT "US/Pacific*" does not keep proper time.
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4125
Location: holland

PostPosted: Mon 25 Feb 2019, 14:42    Post subject:  

I use this for to geolocate timezone (will set the timezone automatically, according to where you are):
https://github.com/cdown/tzupdate
But note that python is required to have installed.
Just downloaded tzupdate.py :
https://github.com/cdown/tzupdate/raw/develop/tzupdate.py
(right click > Save link as)
Put it in /usr/local/bin and make executable:
Code:
chmod +x /usr/local/bin/tzupdate.py


Then create bash script that runs tzupdate.py followed by ntpdate :
Code:
/usr/local/bin/tzupdate.py
sleep 1
ntpdate -s ntp.ubuntu.com


There must be a working network connection before running this.
Best is to let it scan for connection first, so then becomes like this:
Code:
#!/bin/bash
check_network () {
busybox ping -c1 duckduckgo.com 2> /dev/null
    if [[ $? -ne 0 ]]; then
echo "No network connection yet..."
fi

while true
do
busybox ping -c1 duckduckgo.com 2> /dev/null
    if [[ $? -eq 0 ]]; then
echo "Connected"
break
    fi
    sleep 2
done
}
export -f check_network

/bin/bash -c check_network

/usr/local/bin/tzupdate.py
sleep 1
ntpdate -s ntp.ubuntu.com


-----------------------------------------------

Probably similar thing (to get your timezone) can be done without python, just bash, e.g. :
Code:
curl --request GET \
  --url https://freegeoip.app/json/ \
  --header 'accept: application/json' \
  --header 'content-type: application/json'

And then extract the timezone from the output.
EDIT: This should do to extract:
Code:
TZ=$(curl -s --request GET --url https://freegeoip.app/json/ --header 'accept: application/json' --header 'content-type: application/json' | tr ',' '\n' | grep "time_zone" | cut -d ":" -f2|sed s'/.$//;s/"//')
echo $TZ         # display timezone


Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14414
Location: Gatineau (Qc), Canada

PostPosted: Wed 17 Apr 2019, 00:46    Post subject:  

Hi Fredx.

Your script does what, besides telling us the timezone? I'm not sure that
I understand. Besides I have a deep hate of all snakes, without
discrimination, even computer ones!

Does your script set the time?
Of course I'm partial to using my own htpdate script! Wink

BFN.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4125
Location: holland

PostPosted: Wed 17 Apr 2019, 03:16    Post subject:  

Hi musher0

Quote:
Your script does what, besides telling us the timezone?

Running the python script will set the timezone automatically to yours.
And then followed by ntpdate command, the correct time will be set

Code:
/usr/local/bin/tzupdate.py
sleep 1
ntpdate -s ntp.ubuntu.com


But there are more ways to set the timezone and time of course, I just like this one because it's all done automatically.

Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14414
Location: Gatineau (Qc), Canada

PostPosted: Wed 17 Apr 2019, 15:19    Post subject:  

Hi fredx.

Thanks for the explanation. htpdate does it in one go.

BFN.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4125
Location: holland

PostPosted: Wed 17 Apr 2019, 16:53    Post subject:  

musher0 wrote:
Hi fredx.

Thanks for the explanation. htpdate does it in one go.

BFN.


From what I tested it depends on the timezone correctly set. It doesn't "know" where you are.
E.g. if I set timezone wrong, or to UTC, htpdate goes along with how it is set.
Actually same as how ntp works, it also needs the timezone to be set to your location.

Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4125
Location: holland

PostPosted: Sun 04 Aug 2019, 06:41    Post subject:  

I found that the code to get timezone and sync with ntpdate from here http://murga-linux.com/puppy/viewtopic.php?p=1019617#1019617 using python script tzupdate.py doesn't always work (dependency python-requests required).
So here's a bash-only script that should do (but curl and ntpdate are required to be installed).

Also changed the way to check for network connection (using curl rather than ping, some network admins block ping requests, so using curl is more reliable).

Code:
#!/bin/bash

# automatically get your timezone and set the correct time from internet
# required is a working internet connection and to have ntpdate installed (to sync the time)
# to run at boot, put this script in /root/Startup
# use of curl to check network connection, ping doesn't always work well
 
# check network, wait until there is connection, will stay in loop until there's connection
 case "$(curl -s --max-time 2 -I https://duckduckgo.com | sed 's/^[^ ]*  *\([0-9]\).*/\1/; 1q')" in
  [23]) : ;;
  *) echo "No network connection yet...";;
 esac


while true
do
 case "$(curl -s --max-time 2 -I https://duckduckgo.com | sed 's/^[^ ]*  *\([0-9]\).*/\1/; 1q')" in
  [23]) echo "Connected !"; break;;
  *) : ;;
 esac
sleep 3
done

# get your timezone (from https://freegeoip.app)
TZONE=$(curl -s --request GET --url https://freegeoip.app/json/ --header 'accept: application/json' --header 'content-type: application/json' | tr ',' '\n' | grep "time_zone" | cut -d ":" -f2|sed s'/.$//;s/"//')
echo $ZONE

# set the timezone
if [ -f "/usr/share/zoneinfo/$TZONE" ]; then
ZONEFOUND=yes
   ln -sf /usr/share/zoneinfo/$TZONE /etc/localtime
   echo $TZONE > /etc/timezone
   Xdialog --title " " --msgbox "$(gettext 'Timezone set to '$TZONE'.')" 0 0 &
else
   Xdialog --title " " --msgbox "$(gettext 'Zone not exist! Cannot synchronize time.')" 0 0
fi

sleep 1

# synchronize time using ntpdate
[ $ZONEFOUND = yes ] && ntpdate -s ntp.ubuntu.com   


Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 2 of 2 [25 Posts]   Goto page: Previous 1, 2
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0605s ][ Queries: 13 (0.0086s) ][ GZIP on ]