The function where the initscript calculates the default ntp server for ntpdate is wrong: The " grep '^[server|peer]' /etc/ntp.conf " function already does something wrong.I guess the idea was lines which either start with "server" or with "peer". But using [ ] means you match on a list of characters and not whole strings. For example on my config it gets already multiple lines like: server 192.168.1.6 prefer minpoll 6 maxpoll 10 requestkey 65535 restrict default ignore restrict 192.168.1.6 noquery nomodify notrap nopeer The first line is ok ... the rest is already totaly wrong. You get multiple lines with wrong values in NTPDATESERVERS. and when you access that var without " " it apears empty. And with " " it would have newlines. ntpdate doesn't like both versions. ntpdate doesnt like multiple servers in general. Even if those are valid IPs Using " grep '^[sp]e[re][vr]' " is one possible solution (maybe a bit ugly). But multiple values should be also avoided somehow.
This works better: grep '^\(server\|peer\)'
Ok my final sugestion is: grep -m 1 '^\(server\|peer\)[[:space:]]' /etc/ntp.conf | awk '{print $2}' -m 1 takes care that you only have one match and not mutliline output which breaks on ntpdate. no * after [[:space:]] because with * it also means zero spaces is ok which is wrong because at leats one space is mandatory. The only alternative would be [[:space:]][[:space:]]* but that's really not needed in this case.
i fixed the [] in cvs a while ago multiline server passing to ntpdate works over here ... /etc/ntp.conf: server 199.165.76.11 server ntp-ua.usno.navy.mil cmd run: ntpdate `egrep '^(server|peer)[[:space:]]*' /etc/ntp.conf | awk '{print $2}'` the * was used because the rc script used to be using grep ... i forgot that literals were ignored when using regular grep ... so, i changed the '*' to a '+' ... and ill add the -m 1 even though it works for me :p
actually i lied, i wont add -m 1 ... multiline works over here, and it allows ntpdate to fall back to other servers if the user specified them ...