aboutsummaryrefslogtreecommitdiff
path: root/examples/var_service/ntpd/ntp.script
blob: 76c34bf74aed09353396478d4fb72e06c066a180 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh

# Note that there is no provision to prevent several copies of the script
# to be run in quick succession. In fact, it happens rather often
# if initial syncronization results in a step.
# You will see "step" and then "stratum" script runs, sometimes
# as close as only 0.002 seconds apart.
#
# Script should be ready to deal with this.

dt=`date '+%Y-%m-%d %H:%M:%S'`

if test x"$stratum" != x"" \
&& test x"$poll_interval" != x"" \
&& test 4 -ge "$stratum" \
&& test 128 -le "$poll_interval" \
; then
	echo "`tail -n 199 -- "$0.log" 2>/dev/null`" >"$0.log.$$"
	echo "$dt: $1"\
		"freq_drift_ppm=$freq_drift_ppm"\
		"offset=$offset"\
		"stratum=$stratum"\
		"poll_interval=$poll_interval,"\
		"setting hardware clock"\
		>>"$0.log.$$"
	mv -- "$0.log.$$" "$0.log"
	exec hwclock --systohc
fi

echo "`tail -n 199 -- "$0.log" 2>/dev/null`" >"$0.log.$$"
echo "$dt: $1"\
	"freq_drift_ppm=$freq_drift_ppm"\
	"offset=$offset"\
	"stratum=$stratum"\
	"poll_interval=$poll_interval"\
	>>"$0.log.$$"
mv -- "$0.log.$$" "$0.log"