LinuxPeriodically synchronize time in Linux

Periodically synchronize time in Linux

We will use the ntp and ntpdate packages to achieve this.
These packages should already be installed on most linux systems. If not you can install them by using the below

# on RPM based Red Hat, Fedora, Cent OS
 sudo yum install ntpdate
# on APT based Debian, Ubuntu
 sudo apt-get install ntpdate

Create a log file in the tmp directory to see the time sync data

touch /tmp/ntpdate.log

Create a bash script to sync time called ntpdate and put the below into it

# sync server time
/usr/sbin/ntpdate >> /tmp/ntpdate.log

You can place this script anywhere you like and then set up a cron
I will be putting it into the daily cron directory so that it runs once every day
So my ntpdate script is now in /etc/cron.daily/ntpdate and it will run every day

Make this script executable

chmod +x /etc/cron.daily/ntpdate

Test it by running the script once and look for some output in /tmp/ntpdate.log


In your log file you should see something like

26 Aug 12:19:06 ntpdate[2191]: adjust time server offset 0.272120 sec

Monitor this log for some days to make sure the cron is running fine.
If you need to sync more frequently, you can edit the cron tab and run the script every hour

If this does not work, you can also update the script to ( change paths as required )

# sync server time
echo "------------------------------------------------------------------------"
/sbin/service ntpd stop
/usr/sbin/ntpd -gq
/sbin/service ntpd start


Categories: Linux Tags: , , , ,


  1. June 23, 2016 9:22 pm

    […] tools ntpdate or rdate with cron. A search on that approach led to more detailed explanations by Nayak and LostSaloon. It appeared that these would adequately address the […]

Post a comment

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