ddmitry1973
Posts: 12
Joined: Thu Apr 20, 2017 6:57 am

Raspbian Strech - run script on successful time sync - how?

Thu Oct 04, 2018 11:14 am

Hi all, i'm using Pi 3 with Stretch and timesyncd as NTP client.

Code: Select all

Linux raspberrypi 4.14.34-v7+ #1110 SMP Mon Apr 16 15:18:51 BST 2018 armv7l GNU/Linux
Pi is being switched of and on periodically and connects to internet through usb modem, then synchronizes time.
syslog cut:

Code: Select all

Oct  3 12:36:02 raspberrypi pppd[2756]: primary   DNS address 10.74.32.5
Oct  3 12:36:02 raspberrypi pppd[2756]: secondary DNS address 10.74.32.6
Oct  3 12:36:02 raspberrypi dnsmasq[607]: reading /run/dnsmasq/resolv.conf
Oct  3 12:36:02 raspberrypi dnsmasq[607]: using nameserver 8.8.8.8#53
Oct  3 12:36:02 raspberrypi dnsmasq[607]: using nameserver 10.74.32.5#53
Oct  3 12:36:02 raspberrypi dnsmasq[607]: using nameserver 10.74.32.6#53
Oct  3 12:36:02 raspberrypi dnsmasq[607]: using nameserver 8.8.8.8#53
Oct  3 12:36:02 raspberrypi PPP: Modem connected
Oct  3 12:36:02 raspberrypi kernel: [  617.235549] nf_conntrack version 0.5.0 (15360 buckets, 61440 max)
Oct  3 12:36:06 raspberrypi autossh[2877]: starting ssh (count 1)
Oct  3 12:36:06 raspberrypi autossh[2877]: ssh child pid is 2878
Oct  4 02:47:23 raspberrypi systemd[2434]: Time has been changed
Oct  4 02:47:23 raspberrypi systemd-timesyncd[274]: Synchronized to time server 91.236.251.24:123 (3.debian.pool.ntp.org).
Oct  4 02:47:23 raspberrypi systemd[1]: Time has been changed
I need to run some script only after successful system time synchronization. i.e. at line
"Oct 4 02:47:23 raspberrypi systemd-timesyncd[274]: Synchronized to time server 91.236.251.24:123 (3.debian.pool.ntp.org)." of the log above.

Could somebody advice?
If timesyncd is not an option, may be you can advice another ntp client which allows event scripting?
Or some another approach?

Thanks!

Return to “Beginners”