plugin ntpdate: tolerate multiple NTP servers (e.g. in a pool)

Previously multiple "server" lines were consumed, but the output of the
awk filter lacked the line ending.  Thus the last numeric value of the
previous "server" line was concatenated with the first numeric value of
the following "server" line.  Thus multiple dots occurred in a single
numeric value and parsing just failed.

Thanks, glyndon!

Closes: #16
This commit is contained in:
Lars Kruse 2022-05-04 14:52:44 +02:00
parent 74927fc6e7
commit a2f1745477

View file

@ -11,7 +11,7 @@ fetch_ntpdate() {
OFFSET=0
DELAY=0
if [ -n "$NTP_PEER" ] && [ -x "$NTPDATE" ]; then
DATA=$("$NTPDATE" -q "$NTP_PEER" | awk '/^server.*offset/{gsub(/,/,""); printf "%s %s", ($6*1000), ($8*1000);}')
DATA=$("$NTPDATE" -q "$NTP_PEER" | awk '/^server.*offset/{gsub(/,/,""); printf "%s %s", ($6*1000), ($8*1000); exit;}')
OFFSET=$(echo "$DATA" | cut -d " " -f 1)
DELAY=$(echo "$DATA" | cut -d " " -f 2)
fi