Tiny Core Base > TCB Bugs
getTime.sh not working at startup
Rich:
Hi Stefann
If you want a way to log whether your network is up or down:
--- Code: ---tc@E310:~$ echo "$(date | tr '\n' ' ' && ifconfig | grep -q Bcast && echo Up || echo Down)"
Fri May 2 09:30:33 UTC 2025 Up
tc@E310:~$
--- End code ---
If the network was down, it would have printed:
--- Code: ---Fri May 2 09:30:33 UTC 2025 Down
--- End code ---
Just place something like this where ever you want to test the networks status:
--- Code: ---echo "$(date | tr '\n' ' ' && ifconfig | grep -q Bcast && echo Up || echo Down)" >> /tmp/Network.log
--- End code ---
Paul_123:
Since he can ssh in, I suspect the problem is with name resolution of the ntp server, or ntp just being slow.
Rich:
Hi Paul_123
--- Quote from: Paul_123 on May 02, 2025, 09:56:35 AM ---Since he can ssh in, ...
--- End quote ---
You're probably right, I just wanted to offer a simple command for
logging network status.
Stefann:
1st: thanks Rich for the code-snippets, I'm not good at shell language so it gave a me a toolbox. Thnaks.
With that said...... I did some testing.
My main conclusion: time will only be updated at boot if clock battery is dead.
What i did:
Test1: set date to 1jan 2010 and try to run getTime.sh with sudo >> succeeds
I did not expect that, if i understand man-page correct it needs option -g to succeed with offset above 1000secs
But anyways.... this proofs getTime.sh always updates time even if it's a really big delta
--- Code: ---tc@hp510:~$ sudo date 010101012010
Fri Jan 1 01:01:00 CET 2010
tc@hp510:~$ date
Fri Jan 1 01:01:03 CET 2010
tc@hp510:~$ sudo getTime.sh
tc@hp510:~$ date
Sat May 3 08:01:27 CEST 2025
--- End code ---
Test2: set date to 1jan 2010 and try to run settime.sh with sudo >> succeeds
Note: command took about 3seconds to run (not precise, just counted out loudly)
--- Code: ---tc@hp510:/etc/init.d$ sudo date 010101012010
Fri Jan 1 01:01:00 CET 2010
tc@hp510:/etc/init.d$ date
Fri Jan 1 01:01:03 CET 2010
tc@hp510:/etc/init.d$ sudo ./settime.sh
tc@hp510:/etc/init.d$ date
Sat May 3 08:06:01 CEST 2025
--- End code ---
Test3: set date to 1jan 2016 and try to run settime.sh with sudo >> fails
No update (command now takes only a split second)
--- Code: ---tc@hp510:/etc/init.d$ sudo date 010101012016
Fri Jan 1 01:01:00 CET 2016
tc@hp510:/etc/init.d$ date
Fri Jan 1 01:01:02 CET 2016
tc@hp510:/etc/init.d$ sudo ./settime.sh
tc@hp510:/etc/init.d$ date
Fri Jan 1 01:01:12 CET 2016
--- End code ---
Test4: set date to 1jan 2010 and reboot >> succeeds
Alike test 1 set date to 1jan 2010, reboot.
now time is properly updated.
Analysis/rootcause:
below codesnippet of settime.sh shows it checks whether current date is later than 2015 and breaks without setting date if it is:
--- Code: --- XXX=$(/bin/date -I)
XXX=${XXX:0:4}
if [ "$XXX" -ge "2015" ];
then
break
fi
--- End code ---
This effectively means:
- if clock battery is dead there will be a time update.
- if clock battery is "ok" there will not be a time update.
Whether this is wanted or unwanted behavior is open for discussion.
To be honest, as the update adds 3 seconds to the boot-time (or is it done in the background???) I'm totally ok that it does not.
This implies however that i will need to call sudo getTime.sh regularly with a crontab.
Note: I hope i did everything correct
for completeness & easy reference: full content of settime.sh
--- Code: ---tc@hp510:/etc/init.d$ cat settime.sh
#!/bin/sh
# (c) Robert Shingledecker 2012
# Bela Markus 2015
# Wait for network to come up and then set time
CNT=0
until ifconfig | grep -q Bcast
do
[ $((CNT++)) -gt 60 ] && break || sleep 1
done
if [ $CNT -le 60 ]
then
CNT=9999
NRT=0
while sleep 0
do
XXX=$(/bin/date -I)
XXX=${XXX:0:4}
if [ "$XXX" -ge "2015" ];
then
break
fi
if [ $CNT -gt 10 ];
then
/usr/bin/getTime.sh
if [ $NRT -gt 5 ];
then
break
fi
CNT=0
NRT=$((NRT+1))
fi
CNT=$((CNT+1))
sleep 1
done
fi
--- End code ---
Stefann:
update......
no... its a bit different.
yes, test1,test2,test3 are as I said.
however test4 is slightly different....
test4/redo: set clock to 2010 and reboot >> clock is updated to 2025 BUT has 2h03m offset
--- Code: ---tc@hp510:~$ sudo getTime.sh
tc@hp510:~$ date
Sat May 3 10:17:06 CEST 2025 // note: this is correct
tc@hp510:~$ sudo date 010101012010
Fri Jan 1 01:01:00 CET 2010
tc@hp510:~$ date
Fri Jan 1 01:01:03 CET 2010
tc@hp510:~$ sudo reboot
.........wait........
tc@hp510:~$ date
Sat May 3 12:23:55 CEST 2025 // this is roughly 2h03m wrong
tc@hp510:~$ sudo getTime.sh
tc@hp510:~$ date
Sat May 3 12:24:03 CEST 2025 // even after time update that succeeded earlier still wrong
tc@hp510:~$ sudo getTime.sh
tc@hp510:~$ date
Sat May 3 10:21:18 CEST 2025 // after an other time update it is correct now
tc@hp510:~$
--- End code ---
test5, set clock to 2016 and reboot >> strangely enough, time is updated (???) also with 2h03m offset
strange, so settime.sh I demonstrated to NOT update with year=2016 but now it updates
And again 2h03m wrong
and again time only corrects after second getTime.sh call
--- Code: ---tc@hp510:~$ sudo date 010101012016
Fri Jan 1 01:01:00 CET 2016
tc@hp510:~$ date
Fri Jan 1 01:01:01 CET 2016
tc@hp510:~$ sudo reboot
.........wait........
tc@hp510:~$ date
Sat May 3 12:29:11 CEST 2025 // again... roughly 2h03m wrong
tc@hp510:~$ sudo getTime.sh
tc@hp510:~$ date
Sat May 3 12:29:23 CEST 2025 // again... even after time update that succeeded earlier still wrong
tc@hp510:~$ sudo getTime.sh
tc@hp510:~$ date
Sat May 3 10:26:20 CEST 2025 // again... after an other time update it is correct now
tc@hp510:~$
--- End code ---
I post this now as "intermediate status"
I will think about how to move on this further.
I guess /etc/init.d/tc-config calls even other stuff.
I will look further but "hints" are welcome
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version