ntp-server.sh does not perform version check correctly
aekinskjaldi opened this issue · 4 comments
ntpd --version
from Centos 7 repo gives output to stderr instead of stdout, and thus variable VER remains empty even if version is exactly as mentioned in condition, i.e. 4.2.6p5, and instead of ntpdc
command script tries to execute ntpq
Moreover, ntpdc
does not resolve localhost correctly and gives error
ntpdc: write to localhost failed: Operation not permitted
I rewrote condition this way to make it work
VER=$($BIN_NTPD --version 2>&1 | head -n 1)
if [[ "$VER" == *"4.2.6p5"* ]]; then
USECMD=$(echo "$BIN_NTPDC" -c iostats 127.0.0.1)
else
USECMD=$(echo "$BIN_NTPQ" -c iostats 127.0.0.1)
fi
Looks like it is working properly here for grabbing that version on CentOS 7 under either bash or sh(but both of those working the same is hardly surprising).
[root@elk0]0|/root>sh
sh-4.2# VER=$(ntpd --version 2>&1 | head -n 1)
sh-4.2# echo $VER
ntpd 4.2.6p5
sh-4.2# exit
[root@elk0]0|/root>bash
[root@elk0 ~]# VER=$(ntpd --version 2>&1 | head -n 1)
[root@elk0 ~]# echo $VER
ntpd 4.2.6p5
[root@elk0 ~]# ntpd --version > /dev/null
ntpd 4.2.6p5
[root@elk0 ~]#
Derp. Sorry. Disregard what I said. I see what you mean now.
Thanks. And aye, you are correct.
Tested and looks good. Thanks!
Made all POSIX happy and merged. Thanks!