Jump to content
Server Maintenance This Week. ×

How to force an NTP update from FileMaker?


HazMatt

This topic is 3179 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I manage a fleet of workstations that are all configured to sync time with the NTP server 0.pool.ntp.org.  While there are some Windows workstations in the mix, there are many Macs running OS X Mavericks 10.9.1, and for now I'd like to just focus on the Macs, since that's what my most vocal users are using.

 

Even though I have everything set correctly in System Preferences, (i.e. the 'Set date and time automatically:' checkbox is set, etc.), the computers tend to drift over time.  My own workstation was off by 2 minutes and 1 second today, for instance.  I checked Activity Monitor and 'ntpd' was running with no apparent problems.  BUT, the only way my time would update is if I take a trip to System Preferences > Date & Time.  The moment I enter the Date & Time pref pane, the time updates.  I suspect if I were to restart, it would also work, but I haven't tried that.  We tend to just leave our computers on.

 

I suspect this is a bug with OS X, but I'd like to take the matter into my own hands.  Here's my scripting so far:

 

#Check local time vs. server time

Set Variable [ $time_difference; Value:Get(CurrentHostTimeStamp) - Get(CurrentTimeStamp) ]

If [ Abs($time_difference) > Time(0; 1; 0) ]

    #Time difference is greater than 1 minute

   If [ $$current_workstation_platform = "Mac" ]
      #Attempt to update system clock via shell script

      Perform AppleScript [ Calculated AppleScript: "do shell script "ntpd -g"" ]

      Set Variable [ $time_difference_old; Value:$time_difference ]

      Set Variable [ $time_difference; Value:Get(CurrentHostTimeStamp) - Get(CurrentTimeStamp) ]

      If [ Abs($time_difference) ≤ Time(0; 0; 1) ]

         #Time is now within 1 second and is considered fixed

         //  A notification is sent to me regarding the problem and the fix.

      End If

   End If

End If

If [ WS—workstations::i_TimeDifferenceLocalVsServer ≠ $time_difference ]

   #Time difference is different than recorded on workstation record - Update value

   Set Field [ WS—workstations::i_TimeDifferenceLocalVsServer; $time_difference ]

   If [ Abs(WS—workstations::i_TimeDifferenceLocalVsServer) > Time(0; 1; 0) ]

      #Time difference is greater than 1 minute - Notify admin

      //  A notification is sent to me regarding the problem.

   End If

End If

 

The shell script "ntpd -g" apparently requires sudo access, and the point of this is to silently fix the computer's clock, so it is not reasonable to require this for my unauthorized users.

 

How have others dealt with this issue?

Link to comment
Share on other sites

I have not dealt with this issue but I'm surprised to hear that the clocks drift so much over time. I wonder if you could run ntpd in crontab every night? I think cron runs with admin privileges. You would need admin access to users workstations to set it up and it would take FileMaker out of the loop. (Crontab has been deprecated on Mac OS X in favor of launchd, but it still works fine and is much easier to setup.)

Link to comment
Share on other sites

  • 5 weeks later...

First: this is a known bug. The short story is that Apple changed how they handled time syncing in 10.9 to conserve power: https://discussions.apple.com/message/23924875#23924875

 

Second: If you have access to each of the local machines you can modify the sudoers file so that it doesn't prompt you when entering a password.

In terminal on the local machine:

type "sudo pico /etc/sudoers"

type in the user password

Under the heading "# User privilege specification" add the following line right before the break: "%users ALL=(ALL) NOPASSWD: /usr/loca/sbin/ntpd"

Finally, modify your FM script so that the AppleScript is executing "do shell script "sudo ntpd -g""

 

The change to the sudoers file will now allow any user to execute ntpd as root without having to type in the password.

 

Depending on how your environment is setup, it would be MUCH BETTER to substitute "%users" with the username of the user on that specific computer. But, if the environment is a shared environment and you can't guarantee that a specific user will only be using a specific computer.

Link to comment
Share on other sites

This is good to know. I've noticed my three machines, two on Mavericks and one on Lion, drifting from each other lately in terms of time. Actually even the two on Mavericks, one of which is used as an FMS, is different from my laptop which also runs Mavericks. Messy.

Link to comment
Share on other sites

  • 1 year later...

OK, dead topic, but I'm grateful to @HazMatt for the idea of such a script, and Merlyn. Been facing ongoing same problems and it's dead handy. Another Applescript alternative if you don't mind the administrator password being in plain text in FileMaker: 

do shell script "sudo ntpd -g -q" user name "Administrator User Name" password "------" with administrator privileges

Link to comment
Share on other sites

This topic is 3179 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.