LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-01-2016, 04:24 PM   #1
nuxguy
Member
 
Registered: Oct 2009
Location: Notlob
Distribution: MX Linux
Posts: 41

Rep: Reputation: 0
What time is it ... ??


When does Linux get the date & time during a reboot?

I run a script as a cron using @boot. The script gets the date & time at the beginning and again at the end of the script.

It works perfectly when run by cron timed but when run it using @boot it always seems to get the date & time at the shut down of the previous boot session when it starts then the correct date & time at its end.

I would prefer to "force" Linux to get the updated time when it boots rather than stick a wait in the mix.
 
Old 08-01-2016, 05:09 PM   #2
Rinndalir
Member
 
Registered: Sep 2015
Posts: 733

Rep: Reputation: Disabled
What distro? I thought most set the time from the hardware clock at boot.
 
Old 08-01-2016, 05:34 PM   #3
nuxguy
Member
 
Registered: Oct 2009
Location: Notlob
Distribution: MX Linux
Posts: 41

Original Poster
Rep: Reputation: 0
Distro: MX-15
Yes, i would think that all distro's set the time from either the hardware clock, or possibly a server, during the boot process. However, looking at the output from my cron @boot run script it looks like it does that AFTER it starts cron @boot jobs ... and until it does get a new time, it seems to think it's still about the time the previously booted session ended - yet that simply feels completely wrong to me.
 
Old 08-01-2016, 05:56 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,945

Rep: Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314
Does this happen for both a full shutdown and a reboot? Just to verify this is a physical not virtual machine? Is this a dual boot computer?

Can you check the hardware clock from the BIOS setup page to verify it is incrementing? If not then your clock chip might have died.

The OS should sync the system clock with the hardware clock during the init process. Depends when the services actually start but on my old debian box cron starts before ntp. CentOS is the opposite.
 
Old 08-01-2016, 08:41 PM   #5
Rinndalir
Member
 
Registered: Sep 2015
Posts: 733

Rep: Reputation: Disabled
Quote:
Originally Posted by nuxguy
and until it does get a new time, it seems to think it's still about the time the previously booted session ended - yet that simply feels completely wrong to me.
Embedded systems can be configured to do that in the absence of a clock chip. It's better than Jan. 1 1970 or Dec. 31 1969.

Not much better but a little better.

I do not know MX-15.
 
Old 08-01-2016, 09:19 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,945

Rep: Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314
In addition, you can also examine the hwclock from linux via the hwclock command. You need to be root or use sudo.

hwclock -r
 
Old 08-02-2016, 01:43 PM   #7
nuxguy
Member
 
Registered: Oct 2009
Location: Notlob
Distribution: MX Linux
Posts: 41

Original Poster
Rep: Reputation: 0
michael:

difficult to tell since there's not a lot of time between close & re-start during a reboot.

No, not a virtual machine.

No duel boot. This is the only OS on the hd, excluding a few ISO's of distro's.

I ran "hwclock" as you suggested and it seems to be incrementing ok.

MX is Debian based so what you said about "cron running before ntp on your old deb box" looks like the problem.

I guess a short wait is the best / only solution after all ... unless you know better


Many thanks for your help.
 
Old 08-02-2016, 01:57 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,945

Rep: Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314
The logs should help see the time difference between shutdown and startup. The only other idea at the moment would be to check the battery. You could always move cron to start later.
 
Old 08-02-2016, 02:30 PM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,359
Blog Entries: 4

Rep: Reputation: 3336Reputation: 3336Reputation: 3336Reputation: 3336Reputation: 3336Reputation: 3336Reputation: 3336Reputation: 3336Reputation: 3336Reputation: 3336Reputation: 3336
Distros commonly run ntpd, a network time-synchronization daemon. This will synchronize the clock at startup, and then periodically thereafter to handle "drift."
 
Old 08-02-2016, 02:34 PM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Does MX-15 based on Debian, have an /etc/rc.local?
 
Old 08-02-2016, 02:38 PM   #11
nuxguy
Member
 
Registered: Oct 2009
Location: Notlob
Distribution: MX Linux
Posts: 41

Original Poster
Rep: Reputation: 0
Although my machine is pretty old, it has only been used for a short while. So unless the battery was faulty when it was new, which i think pretty unlikely, it should be fine.
It seems to be the silly way the Debian allows cron to run jobs before it has bothered to decide what day it is ... seems strange to me but i guess the have their reason(s).
Thanks michaelk, you've been a great help ... an eye-opening help.
 
Old 08-02-2016, 02:43 PM   #12
nuxguy
Member
 
Registered: Oct 2009
Location: Notlob
Distribution: MX Linux
Posts: 41

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Habitual View Post
Does MX-15 based on Debian, have an /etc/rc.local?
Yes
 
Old 08-05-2016, 01:43 PM   #13
nuxguy
Member
 
Registered: Oct 2009
Location: Notlob
Distribution: MX Linux
Posts: 41

Original Poster
Rep: Reputation: 0
UPDATE
++++++

Well, sort of ...

So i went into my cron jobs to add a delay and found that i had already coded one in,
e.g.

sudo cron

# Ensure system is kept up-to-date: 11 secs after every reboot - write o/p to a log file
@reboot sleep 11 && /home/me/bin/systemupdate.sh

cron

# Every reboot log our ip - allow plenty time to setup network connection
@reboot sleep 15 && /home/me/bin/logmyip.sh

q1)
Since a 15 second delay is clearly not long enough, how long do you think i should wait?

q2)
Does anyone think, as i do, that having to wait over 15 seconds, something must be wrong?
 
Old 08-05-2016, 02:08 PM   #14
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,945

Rep: Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314
On my old debian box network manager also starts after cron. So check the logs to see how long it takes to acquire an IP address. Are you wired or wireless?

When ntp starts it should force a time sync. Depending on where you are in the world it might help if you select the nearest time pool.
 
Old 08-05-2016, 04:42 PM   #15
nuxguy
Member
 
Registered: Oct 2009
Location: Notlob
Distribution: MX Linux
Posts: 41

Original Poster
Rep: Reputation: 0
hi, michaelk

Wired connection.

And now the Logs ....

First, i don't seem to have a /var/log/cron yet, I thought cron/anacron logged to this file?

Second, when i look at /var/log/boot i'm having problems working-out when the network connection is made.

Is there an easy, "human-able", way to discover this info?

(AntiX MX-15, Debian based)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
user time, system time, real time .. reg chaitanyajun12 Linux - Newbie 7 03-14-2016 05:43 PM
[SOLVED] The system time switches the time zone automatically but doesn't change the time RandomTroll Linux - Software 9 03-15-2013 12:28 PM
how to understand user time, sys time, wait time, idle time of CPU guixingyi Linux - Server 1 08-24-2010 10:10 AM
PAM time restrictions - changing Time.conf so it gets time from sql table noodlesoffire Linux - Newbie 1 04-04-2010 04:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration