You are not logged in.

#1 2013-07-12 03:08:11

LeafStorm
Member
From: North Carolina
Registered: 2009-05-20
Posts: 51
Website

Script for saving time to disk across reboots?

I am fairly certain that my laptop's clock battery has died. Unfortunately, it's a Macbook, so I haven't yet figured out whether I can replace it on my own, and when I will be able to do so. It's possible that I might have a non-working clock for a while.

Everything else works, so once the Internet's up I can use ntpd to resynchronize. But it would be nice if my system didn't boot thinking it was 2001 (if only so Firefox, Dropbox, and Thunderbird don't complain about certificate violations). Is there a program or script that will save the time to disk upon shutdown, and then restore it upon startup if the hardware clock thinks it's some ridiculous time in the past?

(I realize the time will still be wrong, but "within the same month" would be correct enough to avoid running into SSL certificate errors.)


Thanks,
Matthew Frazier

Offline

#2 2013-07-12 03:14:11

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,452
Website

Re: Script for saving time to disk across reboots?

ntpd should be able to run long before you're starting up the programs you list as problematic.

I suspected you would be trying to avoid constant fscks due to bad time stamps (obviously this can't be helped by something saved on disk).

You certainly could write a simple service to store and retreive the time - but why isn't ntpd working?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2013-07-12 03:23:17

LeafStorm
Member
From: North Carolina
Registered: 2009-05-20
Posts: 51
Website

Re: Script for saving time to disk across reboots?

Trilby wrote:

ntpd should be able to run long before you're starting up the programs you list as problematic.

Oh, ntpd works fine. But this is a laptop, and since I use Wicd, it can't connect to the wireless network to download the time until I have logged in. (And since I use Xfce's "session restore" feature, Thunderbird and Firefox tend to start when I log in.)

Trilby wrote:

I suspected you would be trying to avoid constant fscks due to bad time stamps (obviously this can't be helped by something saved on disk).

I haven't noticed any unnecessary fscking, but you're right -- that wouldn't resolve it anyway. The certificate issues are the only problems I have actually noticed, and those are fairly minor.

Trilby wrote:

You certainly could write a simple service to store and retreive the time - but why isn't ntpd working?

I have part of one started in my text editor, and if it's going to be more than a day or so until I can fix the battery, I can finish it myself. I just wanted to know if someone else had written a program that does the same thing, so I wouldn't have to write another.


Thanks,
Matthew Frazier

Offline

#4 2013-07-12 04:58:46

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Script for saving time to disk across reboots?

Why does wicd not connect until you log in?  When I use wicd it connects just fine bfore I log in.

Offline

#5 2013-07-12 05:10:19

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: Script for saving time to disk across reboots?

LeafStorm wrote:
Trilby wrote:

ntpd should be able to run long before you're starting up the programs you list as problematic.

Oh, ntpd works fine. But this is a laptop, and since I use Wicd, it can't connect to the wireless network to download the time until I have logged in. (And since I use Xfce's "session restore" feature, Thunderbird and Firefox tend to start when I log in.)

Since the internet is not connected, how does firefox give a certificate error? Do you not clean your caches?

PS: I got fooled by Trilby's new avatar. I saw someone had replied, then I saw quoted by "Trilby"  and I was like, where is his post? Took another look at the first reply and realized the "issue" tongue

Offline

#6 2013-07-12 10:23:09

LeafStorm
Member
From: North Carolina
Registered: 2009-05-20
Posts: 51
Website

Re: Script for saving time to disk across reboots?

It seems like this thread has become "you shouldn't have a problem" instead of "yeah, I know a program that does this/no, I don't know a program that does this." :-/

WonderWoofy wrote:

Why does wicd not connect until you log in?  When I use wicd it connects just fine bfore I log in.

Not sure. It could just be that I log in faster than it connects.

x33a wrote:
LeafStorm wrote:
Trilby wrote:

ntpd should be able to run long before you're starting up the programs you list as problematic.

Oh, ntpd works fine. But this is a laptop, and since I use Wicd, it can't connect to the wireless network to download the time until I have logged in. (And since I use Xfce's "session restore" feature, Thunderbird and Firefox tend to start when I log in.)

Since the internet is not connected, how does firefox give a certificate error? Do you not clean your caches?

It connects to the network right after I log in, but Firefox and Thunderbird start before ntpd has a chance to reset the time.


Thanks,
Matthew Frazier

Offline

#7 2013-07-12 13:28:07

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Script for saving time to disk across reboots?

You could use netctl and use ExecUpPost=/usr/bin/ntpd -qg so that it will update the time as soon as it connects. But you are still having to wait for the connection to be established before it happens.

I know that NetworkManager also have some kind of a hook like system in which you would set it up to update the time as soon as it connects as well. 

Of course this all assumes that you are okay with being logged in slightly before the connection is established.  If you want the connection to be established before the system fully boots, then you can use either netctl@.service or a combination of wpa_supplicant.service and dhcpcd@.service.

Offline

#8 2013-07-12 13:30:53

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: Script for saving time to disk across reboots?

LeafStorm wrote:

It seems like this thread has become "you shouldn't have a problem" instead of "yeah, I know a program that does this/no, I don't know a program that does this." :-/

That's unfortunately becoming quite common here. hmm


I am not aware of any existing program to do this, so I wrote my own wink
Let me know if this works for you: http://xyne.archlinux.ca/projects/timedatectl-restorer/

I haven't actually tested the service but it should do the trick.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#9 2013-07-12 13:43:03

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,452
Website

Re: Script for saving time to disk across reboots?

LeafStorm wrote:

It seems like this thread has become "you shouldn't have a problem" instead of "yeah, I know a program that does this/no, I don't know a program that does this."

There is a fine line between a response that is unproductive for these reasons, and a response that is exactly what is needed in response to an XY problem.

No one said you shouldn't have a problem.  A couple of us suggested that the problem was really just somewhere else than where you were looking: in how ntpd was configured.  Many of the most productive forum threads are not providing solutions, but just helping the OP pinpoint the problem, at which point the solution becomes obvious.

Last edited by Trilby (2013-07-12 13:44:22)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2013-07-12 14:14:30

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: Script for saving time to disk across reboots?

Trilby wrote:

There is a fine line between a response that is unproductive for these reasons, and a response that is exactly what is needed in response to an XY problem.

No one said you shouldn't have a problem.  A couple of us suggested that the problem was really just somewhere else than where you were looking: in how ntpd was configured.  Many of the most productive forum threads are not providing solutions, but just helping the OP pinpoint the problem, at which point the solution becomes obvious.

I agree with the assessment of how to deal with XY problems, but "ntpd should be able to run long before you're starting up the programs you list as problematic" and "Why does wicd not connect until you log in?  When I use wicd it connects just fine bfore I log in." can be accurately characterized as "X should just work". The follow-up posts were more helpful, but it is understandable that the initial posts leave an impression of unhelpfulness.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#11 2013-07-13 01:11:21

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,131

Re: Script for saving time to disk across reboots?

Although I can see that might be the impression given, I think that often posts of that kind are actually attempts to clarify/understand the problem and to throw out potential strategies which the OP might not have considered.

Last edited by cfr (2013-07-13 01:13:15)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#12 2013-07-14 01:02:32

LeafStorm
Member
From: North Carolina
Registered: 2009-05-20
Posts: 51
Website

Re: Script for saving time to disk across reboots?

Xyne wrote:

I am not aware of any existing program to do this, so I wrote my own wink
Let me know if this works for you: http://xyne.archlinux.ca/projects/timedatectl-restorer/

I haven't actually tested the service but it should do the trick.

Oh wow, thanks! It built and installed fine, but I haven't tested it yet. I'll let you know later what happens.

(Although...why is it calling sys.exit with a string when a CalledProcessError is raised?)


Thanks,
Matthew Frazier

Offline

#13 2013-07-14 05:13:16

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: Script for saving time to disk across reboots?

LeafStorm wrote:

(Although...why is it calling sys.exit with a string when a CalledProcessError is raised?)

http://docs.python.org/3/library/sys.html#sys.exit

In particular, sys.exit("some error message") is a quick way to exit a program when an error occurs.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB