Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Setting time, wi-fi

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
luiznetto
Posts: 67
Joined: 2013-11-26 18:40

Setting time, wi-fi

#1 Post by luiznetto »

Hi all. I run Wheezy on a laptop with wi-fi. I notice there is always a difference between the time shown by my cell phone (12:40 pm now) and that shown by my system clock (12:55 pm now). When I boot my laptop, I'm not connected to the internet yet; I only get connected to the wi-fi network by the Gnome Network Manager after I log into my user account, so it's impossible for my system to get the right time during boot (I think tzdata is the package responsible for this). Any way I can set up automatic time correction after boot and log-in?

Thanks a lot in advance.

User avatar
phenest
Posts: 1702
Joined: 2010-03-09 09:38
Location: The Matrix

Re: Setting time, wi-fi

#2 Post by phenest »

Are you saying that the time never gets corrected? I think you need the ntpdate package.
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D

cronoik
Posts: 310
Joined: 2015-05-20 21:17

Re: Setting time, wi-fi

#3 Post by cronoik »

Post not relevant because it was asked for a solution for wheezy. The following post works only since jessie (due to systemd).
Please run:

Code: Select all

timedatectl
and check if 'NTP enabled' is set to yes. If not, uncomment the servers in vim /etc/systemd/timesyncd.conf and run the following commands:

Code: Select all

systemctl enable systemd-timesyncd.service && systemctl start systemd-timesyncd.service
Last edited by cronoik on 2017-08-14 12:55, edited 1 time in total.
Have a nice day!

luiznetto
Posts: 67
Joined: 2013-11-26 18:40

Re: Setting time, wi-fi

#4 Post by luiznetto »

Hi guys

I did the following (I don't know if I did it right):
I installed ntpdate
Then I edited the file /etc/default/ntpdate:

Code: Select all

# The settings in this file are used by the program ntpdate-debian, but not
# by the upstream program ntpdate.

# Set to "yes" to take the server list from /etc/ntp.conf, from package ntp,
# so you only have to keep it in one place.
NTPDATE_USE_NTP_CONF=yes

# List of NTP servers to use  (Separate multiple servers with spaces.)
# Not used if NTPDATE_USE_NTP_CONF is yes.
NTPSERVERS="0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org"

# Additional options to pass to ntpdate
NTPOPTIONS=""
I removed the ' yes ' on line 6

Now I think I can expect the time to be automatically updated each time I reconnect to the wireless (or cable internet) surface. Am I right?

User avatar
phenest
Posts: 1702
Joined: 2010-03-09 09:38
Location: The Matrix

Re: Setting time, wi-fi

#5 Post by phenest »

You didn't need to edit the file. Open Gnome Settings > Date & Time. It's all there.
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D

User avatar
stevepusser
Posts: 12930
Joined: 2009-10-06 05:53
Has thanked: 41 times
Been thanked: 71 times

Re: Setting time, wi-fi

#6 Post by stevepusser »

cronoik wrote:Please run:

Code: Select all

timedatectl
and check if 'NTP enabled' is set to yes. If not, uncomment the servers in vim /etc/systemd/timesyncd.conf and run the following commands:

Code: Select all

systemctl enable systemd-timesyncd.service && systemctl start systemd-timesyncd.service
It's a Wheezy system...advice for systemd is very unlikely to be of help.
MX Linux packager and developer

User avatar
sjukfan
Posts: 386
Joined: 2010-03-01 19:39

Re: Setting time, wi-fi

#7 Post by sjukfan »

A pretty cheap version would be to use rdate and put this in cron

Code: Select all

@reboot sleep 120 && rdate some.ntp.server.netrdate -nca 0.se.pool.ntp.org
Bullseye amd64, AMD Ryzen 5 3600
Buster amd64, Intel Xeon E3-1240 v3
Sid ppc, PowerPC 7447a
Sid ppc64, PowerPC 970FX

luiznetto
Posts: 67
Joined: 2013-11-26 18:40

Re: Setting time, wi-fi

#8 Post by luiznetto »

It seems to be working! Thanks a lot, guys! I think we can mark this thread as solved. :)

User avatar
phenest
Posts: 1702
Joined: 2010-03-09 09:38
Location: The Matrix

Re: Setting time, wi-fi

#9 Post by phenest »

Given the various solutions provided, could you tell us what you did to make it work. Just so others reading this may benefit.
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D

luiznetto
Posts: 67
Joined: 2013-11-26 18:40

Re: Setting time, wi-fi

#10 Post by luiznetto »

phenest wrote:Given the various solutions provided, could you tell us what you did to make it work. Just so others reading this may benefit.
With pleasure. I only did what I said in my post above: I installed ntpdate, and then I edited /etc/default/ntpdate. And that was all!
cronoik suggested that I run

Code: Select all

timedatectl
but unfortunately I don't have this command in my system. What package does it belong to?
phenest suggested I run Gnome Settings, but I don't have Gnome either, or KDE, I prefer the much lighter and faster LXDE. I use some Gnome and KDE packages, but not the whole system.
There is often more than one solution to a Linux problem, and not everybody likes to edit system files, but I do what works for me.
It was a pleasure to interact with you guys, have a nice day! :)

User avatar
GarryRicketson
Posts: 5644
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: Setting time, wi-fi

#11 Post by GarryRicketson »

Debian 7 wheezy does not have that command , there apparrentlty is a package in wheezy backports, but it is more of a systemd thing, I don't have it either,..but I am running Debian 7,.... in the later versions, like 7.11 it might be useable,
https://manpages.debian.org/jessie/syst ... .1.en.html
I wouldn't want to put that on my Debian Wheezy,...but it's your system.

Code: Select all

garry@debian:~$ timedatectl
bash: timedatectl: command not found
garry@debian:~$ man timedatectl
No manual entry for timedatectl
.garry@debian:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 7.0 (wheezy)
Release:	7.0
Codename:	wheezy
#I just use the 'date' command to set my time, etc. 
garry@debian:~$ date
Thu May  4 11:01:31 CDT 2017
garry@debian:~$ man date
 
---------- edited---------

I just noticed :
http://forums.debian.net/viewtopic.php? ... 04#p642814Postby stevepusser » 2017-04-29 15:37>
It's a Wheezy system...advice for systemd is very unlikely to be of help.
I did not notice at first, but I see Steve all ready pointed this out.

User avatar
phenest
Posts: 1702
Joined: 2010-03-09 09:38
Location: The Matrix

Re: Setting time, wi-fi

#12 Post by phenest »

luiznetto wrote:phenest suggested I run Gnome Settings, but I don't have Gnome
Sorry. I saw you were using Gnome Network Manager and assumed.
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D

luiznetto
Posts: 67
Joined: 2013-11-26 18:40

Re: Setting time, wi-fi

#13 Post by luiznetto »

Does anyone know if there is a Linux command that shows exactly what the BIOS clock shows without having to look at the BIOS? hwclock won't do this for me; besides the fact that it can only be run by root, it gives almost the same output as the date command:

Code: Select all

root@debian-luiz-computer:/home/luiz# hwclock -r
Wed 10 May 2017 11:52:19 AM PDT  -0.625363 seconds
root@debian-luiz-computer:/home/luiz# hwclock --show
Wed 10 May 2017 11:52:29 AM PDT  -0.062860 seconds
root@debian-luiz-computer:/home/luiz# su luiz
luiz@debian-luiz-computer:~$ date
Wed May 10 11:52:39 PDT 2017
I was pretty sure there was a command that did just that that I used a long time ago, but now I can't remember. I've been googling in vain. Can anybody help me? :?:

User avatar
GarryRicketson
Posts: 5644
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: Setting time, wi-fi

#14 Post by GarryRicketson »

I've been googling in vain.
Really ?

Linux command that shows exactly what the BIOS clock shows
First hit:
http://www.thegeekstuff.com/2013/08/hwc ... ce=tuicool
1. Display Hardware Clock Date and Time

Just type hwclock, which will display the date and time of your system’s hardware clock. This is the same date and time that you’ll see from the BIOS screen. You can also use option -r, or –show to display the date and time.

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: Setting time, wi-fi

#15 Post by Dai_trying »

If you have your hardware clock set to UTC you can just date -u

luiznetto
Posts: 67
Joined: 2013-11-26 18:40

Re: Setting time, wi-fi

#16 Post by luiznetto »

You're wrong, sir, the commands hwclock, hwclock -r, hwclock -- show and date all give the same output:

Code: Select all

root@debian-luiz-computer:/home/luiz# hwclock
Wed 10 May 2017 12:43:22 PM PDT  -0.297209 seconds
root@debian-luiz-computer:/home/luiz# su luiz
luiz@debian-luiz-computer:~$ date
Wed May 10 12:43:46 PDT 2017

luiznetto
Posts: 67
Joined: 2013-11-26 18:40

Re: Setting time, wi-fi

#17 Post by luiznetto »

This is a little bit confusing, isn't it? I know that my hardware clock shows something different from the time where I am now (San Francisco), and it probably shows utc, but what if there was a difference between what my hardware clock shows and utc? What if my hardware clock was set by someone to the time in Paris or Moscow? The man pages for both date and hwclock are not very clear. I wish they stated clearly, this command shows what is in your BIOS clock. Period. Nothing more than that.

luiznetto
Posts: 67
Joined: 2013-11-26 18:40

Re: Setting time, wi-fi

#18 Post by luiznetto »

Here is the man page for hwclock:

Code: Select all

NAME
       hwclock - query or set the hardware clock (RTC)

SYNOPSIS
       hwclock [function] [option...]

DESCRIPTION
       hwclock  is a tool for accessing the Hardware Clock.  You can display the current time, set the Hardware
       Clock to a specified time, set the Hardware Clock from the System Time, or set the System Time from  the
       Hardware Clock.

       You  can also run hwclock periodically to add or subtract time from the Hardware Clock to compensate for
       systematic drift (where the clock consistently loses or gains time at a certain rate when left to run).

FUNCTIONS
       You need exactly one of the following options to tell hwclock what function to perform:

       -r, --show
              Read the Hardware Clock and print the time on standard output.  The time shown is always in local
              time,  even if you keep your Hardware Clock in Coordinated Universal Time.  See the --utc option.
              Showing the Hardware Clock time is the default when no function is specified.
The time shown is always in local
time, even if you keep your Hardware Clock in Coordinated Universal Time

User avatar
GarryRicketson
Posts: 5644
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: Setting time, wi-fi

#19 Post by GarryRicketson »

The instructions are not confusing here,: http://www.thegeekstuff.com/2013/08/hwc ... ce=tuicool
and it says very clearly :
This is the same date and time that you’ll see from the BIOS screen.
from : http://www.thegeekstuff.com/2013/08/hwc ... ce=tuicool
This is the same date and time that you’ll see from the BIOS screen.
1. Display Hardware Clock Date and Time

Just type hwclock, which will display the date and time of your system’s hardware clock. This is the same date and time that you’ll see from the BIOS screen. You can also use option -r, or –show to display the date and time.
It does also go on to say:
Note: The output of the date command might be same as the output of the hwclock command (actually it should be the same). But, the date command gets the date and time from the clock managed from Linux kernel. This in example, there is around 10 mins difference between them.
So yes, they might be the same, in fact they should be.
But if they are not, the same tutorial goes on to explain setting it properly.
The OP just needs to read it.
Postby luiznetto » 2017-05-10 13:13
This is a little bit confusing, isn't it?

Not really, it is pretty clear in the tutorial.
Re: Setting time, wi-fi

Postby Dai_trying » 2017-05-10 12:57
If you have your hardware clock set to UTC you can just date -u
This is correct, read the :

Code: Select all

man date
$ man date
DATE(1) General Commands Manual
-----snip--------------------
-u Display or set the date in UTC (Coordinated Universal) time.
Postby luiznetto » 2017-05-10 13:13
This is a little bit confusing, isn't it? I know that my hardware clock shows something different from the time where I am now (San Francisco), and it probably shows utc, but what if there was a difference between what my hardware clock shows and utc? What if my hardware clock was set by someone to the time in Paris or Moscow? The man pages for both date and hwclock are not very clear. I wish they stated clearly, this command shows what is in your BIOS clock. Period. Nothing more than that.
This is why the hardware should be set to UTC, you don't seem to be sure of this, and then proceed to throw in all kinds of "What if " things,...that is what is making it confusing, Why are you doing that ?
What if my hardware clock was set by someone to the time in Paris or Moscow?
Well simply set it to UTC. Stop making something confusing, when it really is simple.

Post Reply