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.)

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.

Re: Script for saving time to disk across reboots?

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"

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.

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.

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."

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.

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.

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.