setTimeServer etc/ntp.conf doesn't exist ???

tcandela
Valued Contributor II

I am using the setTimeServer.sh script provided by JAMF. When I look in /etc/ is see ntp.conf and when i vi ntp.conf it says in the file ; server time.apple.com

i'm on the east coast and it is set to west coast time and Cupertino, CA time zone

all other enrolled macs are getting the script fine and i do not see this log message for others.

On this one newly imaged mbpro I am getting the following log message.

Script result: Setting network time server to: ntp.blobface.xxx...
2015-03-09 12:44:36.026 systemsetup[2384:507] ** -[ADMNetworkTimeClient _ntpSetEnabled:] /etc/ntp.conf doesn't exist. You need to create it first before ntpd can start sucesfully
setNetworkTimeServer: ntp.blobface.xxx
Network Time is already on.

1 ACCEPTED SOLUTION

nessts
Valued Contributor II

while that command does not return and error @stevewood i think if you actually look at /etc/ntp.conf you will see that its not a valid format

I am pretty sure that
server time.apple.com,myserver.abc.com

is invalid for ntp at least looking at some online documentation about it.
my link text

and running ntpq -p before and after seems to show the config as broken...
hpusmo001:~ etodnes$ ntpq -p

remote refid st t when poll reach delay offset jitter

*time6.apple.com 17.107.131.11 2 u 330 512 1 40.224 0.550 2.011
hpusmo001:~ etodnes$ sudo systemsetup -setnetworktimeserver time.apple.com,mytimeserver.abc.net
setNetworkTimeServer: time.apple.com,mytimeserver.abc.net
hpusmo001:~ etodnes$ ntpq -p
No association ID's returned

View solution in original post

18 REPLIES 18

davidacland
Honored Contributor II
Honored Contributor II

Not sure if there is anything different about that particular Mac but you could just add

touch /private/etc/ntp.conf

To the start of the script to make sure it's there.

GaToRAiD
Contributor II

Try this:

#!/bin/sh

# Use "/usr/sbin/systemsetup -listtimezones" to see a list of available list time zones.
TimeZone="America/New_York"
TimeServer1="internalserver.com"
TimeServer2="time.apple.com"

############# Pause for network services #############
/bin/sleep 10
#################################################

/usr/sbin/systemsetup -setusingnetworktime off 

#Set an initial time zone
/usr/sbin/systemsetup -settimezone $TimeZone

#Set specific time servers
/usr/sbin/systemsetup -setnetworktimeserver $TimeServer1
echo "server $TimeServer2" >> /etc/ntp.conf

# enable location services
/bin/launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist
uuid=`/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57`
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.$uuid LocationServicesEnabled -int 1
/usr/sbin/chown -R _locationd:_locationd /var/db/locationd
/bin/launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist

# set time zone automatically using current location 
/usr/bin/defaults write /Library/Preferences/com.apple.timezone.auto Active -bool true

/usr/sbin/systemsetup -setusingnetworktime on 

/usr/sbin/systemsetup -gettimezone
/usr/sbin/systemsetup -getnetworktimeserver

exit 0

tcandela
Valued Contributor II

Does Ntp.conf reflect what time server is set at? So would my Ntp.conf just say. Ntp.blobface.xxx ?

On the computers that have the script run correctly it is setting the time zone to my current location of Washington DC, which is correct and the time is correct

What is this echo line for?

set specific time servers

/usr/sbin/systemsetup -setnetworktimeserver $TimeServer1
echo "server $TimeServer2" >> /etc/ntp.conf

tcandela
Valued Contributor II

GaToRaid - on a computer or two I get the following information in the LOG after my policy runs that uses the script you provided. Have you seen this before? what does it mean? doesn't seem to harm anything anyways.

Script result: setUsingNetworkTime: Off
Set TimeZone: America/New_York
setNetworkTimeServer: ntp.blobface.xxx
2015-03-11 11:18:24.362 system_profiler[10090:226920] platformPluginDictionary: Can't get X86PlatformPlugin, return value 0
2015-03-11 11:18:24.364 system_profiler[10090:226920] platformPluginDictionary: Can't get X86PlatformPlugin, return value 0
setUsingNetworkTime: On
Time Zone: America/New_York
Network Time Server: ntp.blobface.xxx

GaToRAiD
Contributor II

@tcandela sorry for the delayed. Yes this error will be a problem since you are not enabling location services. Which OS are you running this on?

tcandela
Valued Contributor II

Isn't the script enabling location services ? i see the check box checked in the 'privacy' section to enable location services. what problem is the log telling ?

these computers are mostly ethernet connected, in the TIME ZONE TABE it says 'turn on wifi to determine your current location'

I am running this on 10.7 10.8 10.9 10.10

so far on 32 computers that the script ran on, 3 computers got this message in the log

1 - MBAir 13" mid 2011 10.10.2
2 - iMac early 2009 10.10.2
3 - iMac (21.5-inch, Mid 2011) 10.10.1

also, on some computer after the policy with this script runs etc/ntp.conf lists both ntp servers server ntp.blobface.xxx
server time.apple.com
while on others it lists just
server ntp.blobface.xxx

and the system preferences date & Time has both time servers in the text box ntp.blobface.xxx, time.apple.com
while on others it lists just ntp.blobface.xxx

GaToRAiD
Contributor II

@tcandela ah you are right regarding the location services, we do turn that on with this script(sorry been at a conference for the last week, my head is a bit of mush.)

As for the issue that you are seeing is something to do with system profiler. Try running the command manually without the grep in it(i.e. /usr/sbin/system_profiler SPHardwareDataType) and see if you are able to return something.

And regarding the servers not getting listed, I would try and manually run the script one line at a time and see what results. I haven't had this issue before.

tcandela
Valued Contributor II

From the command line What I get when running the /user/sbin/sysyem_profiler SPHardwareDataTpe is the same message as above, plus hardware overview information.

When I run it from the CL with Grep in it , I get the same two lines, plus a third line displaying the Hardware UUID

What is this line supposed to do?
Seems to be happening only on yosemite

tcandela
Valued Contributor II

From CL When I run sudo server Ntp.blobface.xxx >> /etc/ Ntp.conf ( with or without sudo)
I get. -bash: /etc/Ntp.conf: permission denied

This is from 10.10.2. System

nessts
Valued Contributor II

should be something more like

sudo sh -c "echo ntp.blobface.xxx >> /etc/ntp.conf"

tcandela
Valued Contributor II

nessts - I ran the command your provided from the CL on a computer that did not get both servers added to the ntp.conf file, and it worked

sudo sh -c "echo server ntp.blobface.xxx >> /etc/ntp.conf"

should i revamp the script section to what you see below?
CASPER doesn't need sudo so leave it out ? also the quotes go from "server ..... .conf" ?

Set specific time servers

/usr/sbin/systemsetup -setnetworktimeserver $TimeServer1
sh -c echo "server $TimeServer2 >> /etc/ntp.conf"

nessts
Valued Contributor II

well it all depends how and what you are trying to do. running it from the command line is wholly different than doing it in a casper policy,
you do not need the sudo sh -c and the 2 "
I was just helping you fix your command line issue.
you don't even have to use sysetemsetup to do the first one if you don't want to. The script looked to be correct as it was.

tcandela
Valued Contributor II

trying to figure out why this line works on some computers and not others

echo "server $TimeServer2" >> /etc/ntp.conf

stevewood
Honored Contributor II
Honored Contributor II

@tcandela A better way to set time servers, time zone, etc:

systemsetup -settimezone America/Chicago

# enable network time
systemsetup -setusingnetworktime on

# set the time server
timeServer='time.apple.com'
systemsetup -setnetworktimeserver $timeServer

That's the method I use, and I haven't had a problem using that method since 10.6.

stevewood
Honored Contributor II
Honored Contributor II

I realized that you were trying to set two time servers. According to this discussion on JAMF Nation:

Best way to set multiple NTP servers in 10.7.x and 10.8.x?

You can use systemsetup and just put a comma between the servers:

systemsetup -setnetworktimeserver $timeServer1,$timeServer2

nessts
Valued Contributor II

while that command does not return and error @stevewood i think if you actually look at /etc/ntp.conf you will see that its not a valid format

I am pretty sure that
server time.apple.com,myserver.abc.com

is invalid for ntp at least looking at some online documentation about it.
my link text

and running ntpq -p before and after seems to show the config as broken...
hpusmo001:~ etodnes$ ntpq -p

remote refid st t when poll reach delay offset jitter

*time6.apple.com 17.107.131.11 2 u 330 512 1 40.224 0.550 2.011
hpusmo001:~ etodnes$ sudo systemsetup -setnetworktimeserver time.apple.com,mytimeserver.abc.net
setNetworkTimeServer: time.apple.com,mytimeserver.abc.net
hpusmo001:~ etodnes$ ntpq -p
No association ID's returned

stevewood
Honored Contributor II
Honored Contributor II

Ah, right you are @nessts! I simply found that info in that discussion, and didn't verify the info was correct. Thanks for correcting me Todd!

nessts
Valued Contributor II

that is what I am here for trying to bring a little Unix sense to a Mac world. :)