WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: getTime.sh / ntp  (Read 5093 times)

Offline onelife

  • Full Member
  • ***
  • Posts: 141
getTime.sh / ntp
« on: November 12, 2013, 09:41:19 AM »
Hi Guys,

I'm trying to solve the getTime.sh / ntp issue.

Currently here in South Africa the getTime.sh script does not work :(

Does anyone know how you can use getTime to access a local network ntpd server.

I have a ntp server on the network so ideally I would like to access that.

I've tried using the different "switches" -s for local and / or simply the address 192.168.1.3 with wait -w 20 but no luck.

Do you know if the getTime.sh script will actually talk to a "normal" ntpd server?

Also, another thought - It would be great if there was a way to "save" the system time at point of reboot. IOW, perhaps a way you "pipe" the date into a file and then on start, re-read the date initially from that file before even trying getTime.sh? Just a thought as that would help me on reboot when no internet is available on start up. (I know this means there will be a discrepancy in the time it takes to reboot, but this I can live with rather than the default 1970 date that gets set on startup)

Thanks in advance and chat soon :)
« Last Edit: November 12, 2013, 10:47:55 AM by onelife »

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: getTime.sh / ntp
« Reply #1 on: November 12, 2013, 02:05:47 PM »
Do you know if the getTime.sh script will actually talk to a "normal" ntpd server?
No, it's making use of 'daytime' (port 13).
Quote
Also, another thought - It would be great if there was a way to "save" the system time at point of reboot. IOW, perhaps a way you "pipe" the date into a file and then on start, re-read the date initially from that file before even trying getTime.sh? Just a thought as that would help me on reboot when no internet is available on start up. (I know this means there will be a discrepancy in the time it takes to reboot, but this I can live with rather than the default 1970 date that gets set on startup)
Simply setting system time according to some external clock with the 'date' command seems like a lesser evil IMHO.
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline onelife

  • Full Member
  • ***
  • Posts: 141
Re: getTime.sh / ntp
« Reply #2 on: November 13, 2013, 03:04:31 AM »
Heyo

Thanks for the reply - Sadly I don't have a RTC on the Pi (Yet) ... Am looking into this and will likely happen in the next few months BUT I really need to try solve the time / date issue now for a few systems I already have.

Do you know what it would take to get a ntp client working on PiCore? I see there is a tcz for the "standard TC".

Thanks again.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: getTime.sh / ntp
« Reply #3 on: November 13, 2013, 03:28:24 AM »

Do you know what it would take to get a ntp client working on PiCore? I see there is a tcz for the "standard TC".


1) Wait a bit
2) Create yourself

:)
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: getTime.sh / ntp
« Reply #4 on: November 13, 2013, 06:22:41 AM »
A temporary remedy could be to download a statically linked busybox binary which should include ntpd from here:
http://busybox.net/downloads/binaries/latest/

Something like
Code: [Select]
sudo busybox-i686 ntpd -ndqp time.nist.govworks for me, obviously tested with x86 though.
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: getTime.sh / ntp
« Reply #5 on: November 13, 2013, 06:47:01 AM »
Another quick method could be:
Code: [Select]
sudo rdate some.time.serverAt least in Core x86 rdate is included in base already, so no need to install anything.
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: getTime.sh / ntp
« Reply #6 on: November 13, 2013, 11:51:59 AM »
ntp is running here on the Pi, I will add it to repo in a day.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline ovacikar

  • Newbie
  • *
  • Posts: 42
Re: getTime.sh / ntp
« Reply #7 on: December 29, 2023, 10:43:35 AM »
For anyone landing on this page via Google etc, there is a simpler way of setting the time using any web server with curl and busybox:

sudo busybox date  -D '%d %b %Y %H:%M:%S' -s "`curl -ks --head https://8.8.8.8 | grep '^Date:' | cut -d' ' -f 3-6`"

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11027
Re: getTime.sh / ntp
« Reply #8 on: December 29, 2023, 11:42:10 AM »
I don't think you need curl, you can send a HEAD request using nc.
The only barriers that can stop you are the ones you create yourself.

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 697
Re: getTime.sh / ntp
« Reply #9 on: December 29, 2023, 02:26:40 PM »
Or even use busybox wget ??

Code: [Select]
./busybox wget -q --spider -S --no-check-certificate https://dns.google

Offline ovacikar

  • Newbie
  • *
  • Posts: 42
Re: getTime.sh / ntp
« Reply #10 on: December 29, 2023, 02:57:35 PM »
Or even use busybox wget ??

Code: [Select]
./busybox wget -q --spider -S --no-check-certificate https://dns.google

Needed to redirect stderr to stdout, and readjust the spacing:

sudo busybox date  -D '%d %b %Y %H:%M:%S' -s "`busybox wget -O - --spider -S  --no-check-certificate https://dns.google  2>&1 | grep 'Date' | cut -d' ' -f 5-8`"

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 697
Re: getTime.sh / ntp
« Reply #11 on: December 29, 2023, 04:42:40 PM »
And you can even use the more modern way without using the backtick characters.

Code: [Select]
sudo busybox date -D '%d %b %Y %H:%M:%S' -s "$(busybox wget -q -O - --spider -S --no-check-certificate https://dns.google 2>&1 | grep 'Date' | cut -d' ' -f 5-8)"