Script for synchronizing the clock with Domain Controller

Hi Everyone,

In our environment, we have Mac machines which are joined to window’s domain. Once in while machine will not log on to domain because the OS clock had a different time than the domain controller and sooner you fix the clock, machine will start communicating with domain controller.

I was wondering if there is an easier way to do this using script which can run every few hours to force the OS clock to synchronize with the domain controller.

Thanks,

Hi,

of course you can set date and time, but how do you get the information from the windows domain?

I don’t know exactly but currently we manually set the time and date. May be using AdmitMac (the application we use to bind our Macs to windows domain) but again not sure how would I use this app to check the time from time server.

Thanks,

If you look in System Preferences under Date & Time, you’ll see that you can set the Mac to automatically set the date & time. There are preset time servers, but I believe you can change them to another time server, possibly the one that the PCs are using.

I have looked under system preference and Date and Time settings but there are only 3 time servers (America, Asia and Europe). I was unable to find any place where I can edit those entries or even add another timer server.

Thanks,

It’s Apple, just type it in :wink:

Thank you, I just typed in that field and it took our timer server and set the time accordingly. Now how do I do this using apple script:

Enter the the specific server name and place a check mark in “Set Date and time automatically” field

Thanks,

there is a quite easy way in Leopard


do shell script "/usr/sbin/systemsetup -setnetworktimeserver time.euro.apple.com -setusingnetworktime on"

replace time.euro.apple.com with your time server

Thank you. Tested this script under Leopard and it works great. Do you know if this will work under Tiger as well?

Where can I place this script so that it can run every few hours automatically without any user interaction?

Thanks,

No, systemsetup is new in Leopard.
There is no shell equivalent in Tiger.

The smartest way for a scheduler is a launchd agent in the main library

Hello Stefan,

Tiger’s `systemsetup’ is found under “/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup”
The following script is OK for me…

set the hexData to system attribute "sysv"
set hexString to {}
repeat 4 times
	set hexString to ((hexData mod 16) as string) & hexString
	set hexData to hexData div 16
end repeat
set OS_version to hexString as integer
if OS_version > 1040 then
	if OS_version < 1050 then
		set util to "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup"
	else
		set util to "/usr/sbin/systemsetup"
	end if
	do shell script util & space & "-setnetworktimeserver time.euro.apple.com -setusingnetworktime on" user name "?????" password "¢¢¢¢¢¢" with administrator privileges
end if

Thanks, good to know

shorter version of your script :wink:


set OS_version to ((system attribute "sysv") mod 4096 div 16)
if OS_version < 4 then return
if OS_version = 4 then
	set util to "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup"
else
	set util to "/usr/sbin/systemsetup"
end if
do shell script util & space & "-setnetworktimeserver time.euro.apple.com -setusingnetworktime on" user name "?????" password "¢¢¢¢¢¢" with administrator privileges

… Increasingly shorter :cool:

set OS_version to ((system attribute "sys2")
...

(*
  gestaltSystemVersionMajor     = 'sys1'
  gestaltSystemVersionMinor     = 'sys2'
  gestaltSystemVersionBugFix    = 'sys3'
*)