PDA

View Full Version : Auto update time on Linux (VPS)



SIM
03-07-2013, 06:25 AM
These are my steps that I have been doing to get my Red Hat Linux system clock updated in the crontab with one of the time server using rdate.

What is rdate?

man rdate to read more
rdate connects to an RFC 868 time server over a TCP/IP network, printing the returned time and/or setting the system clock using port 37.

You can check out the time servers used by the NIST Internet Time Service (ITS) at:
http://www.boulder.nist.gov/timefreq...e-servers.html
I will be using time.nist.gov time server as an example in this thread and you are free to use any time server you preferred

If you have firewall installed, please set to allow port 37 TCP connection.

Step 1: login to your server via SSH and gain root access.

Step 2: check whether rdate is installed:

Code:
rpm -qa | grep rdateIf it is not install, kindly please install rdate before continue.

Step 3: add the following in your /etc/crontab file:

Code:
# synchronize system time on every 6AM daily with time server
00 6 * * * root rdate -s time.nist.govYou can do this by cut and paste the following command:

Code:
cat >> /etc/crontab << "EOF"
# synchronize system time on every 6AM daily with time server
00 6 * * * root rdate -s time.nist.gov && /sbin/hwclock --systohc
EOFIf you want to update your system & hardware time now, issue the following command in SSH:

Code:
rdate -s time.nist.gov
/sbin/hwclock --systohcHope this helps

---------------------
This is another way of doing it but you can't specify when to synchronize your server/system clock/time though

Step 1: Gain root access via SSH to your server.

Step 2: Check whether rdate is installed.

Code:
rpm -qa | grep rdateIf rdate is not install, please install it before continue.

Step 3: Create a shell script, chmod it to executable and place it into /etc/cron.daily directory with the below content.

Code:
#!/bin/sh
rdate -s time.nist.gov
/sbin/hwclock --systohcFor me, I create /etc/cron.daily/rdate file directly using the following command:

Code:
cat > /etc/cron.daily/rdate << "EOF"
#!/bin/sh
rdate -s time.nist.gov
/sbin/hwclock --systohc
EOF

chmod +x /etc/cron.daily/rdateHope this helps

ghsoftwares
03-08-2014, 02:22 PM
Thank you for this best tips.