Setting time on a Linux client from a Windows PDC

You can set the time on a linux client using NTP, using the ntpd daemon. For a quick and dirty approach you can use the deprecated ntpdate command. The following script will set the time on the pc

cat /usr/local/bin/syncclock
#!/bin/bash
/usr/sbin/ntpdate -s nl.pool.ntp.org
/sbin/hwclock --adjust
/sbin/hwclock --systohc

If you are running a Linux Client on a windows network where there is no access to a NTP server, you might want to use the samba command net time to get the time and net time set to set it. Adding the following command to the roots crontab file will set the time on your linux bot against the windows primary domain controller each afternoon.

* 12 * * * net time set > /dev/null 2>&1

If you run net time and it reports “Could not locate a time server.  Try specifying a target host.” you may need to specify the address of your Primary Domain Controller. If you don’t know the name of the PDC in your domain, you can find it by typing net time on a windows server. The response will include the address of the PDC.

C:\>net time
Current time at \pdc.example.com is 8/23/2011 1:12 PM

The command completed successfully.

Now you can modify your crontab to include the server name

* 12 * * * net time set --server=192.168.1.100 > /dev/null 2>&1
This entry was posted in General and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *