Of course /pr_home/Device_restart_history.txt is written on an USB stick (Extroot) in order to keep it among reboots; it works, but not as I expected about timestamps:
--> System log.
-rw-r--r-- 1 root root 52 Dec 24 17:47 Device_restart_history.txt ---> The file.
*** Device restarted on*** 2023-12-24_17:47:31 --> Its content.
Is it possible to record the reboot just after the init complete event?
In other words, how can I have my file and its content timestamps on Fri Dec 29 instead of Sun Dec 24?
You probably need to wait for a successful ntp sync. The problem is that most of these devices lack a real time clock, so the initial time is set to the latest timestamp of files written to the storage.
Consider adapting a similar solution for your situation by waiting to write that log entry until ntp sync is complete.
Stratum action happens quite often, always when the reliability level of the ntp server used changes. (Stratum means how many intermediate NTP servers before an official atomic clock at stratum 0.)
That may happen quite often if you have a server pool, like the ntp aliases that we use.
You might simplify things by using "step" ntp hotplug action instead of "stratum". It is triggered when the NTP daemon originally gets a time from internet.
Interesting... so, if I correctly understand your hint, to reach my goal I could use instead a very simple /etc/hotplug.d/ntp/20-Device_restart_history.sh containing: