Web Hosting Talk







View Full Version : Synchronize Your Red Hat Linux Server/System Clock/Time using rdate


choon
02-01-2004, 04:41 PM
Hi everyone,

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/service/time-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:
rpm -qa | grep rdate
If it is not install, kindly please install rdate before continue.

Step 3: add the following in your /etc/crontab file:
# synchronize system time on every 6AM daily with time server
00 6 * * * root rdate -s time.nist.gov
You can do this by cut and paste the following command:
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
EOF

If you want to update your system & hardware time now, issue the following command in SSH:
rdate -s time.nist.gov
/sbin/hwclock --systohc

Hope this helps ;)

Thanks.

Kindest regards,
Choon

choon
02-01-2004, 04:47 PM
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.
rpm -qa | grep rdate
If 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.
#!/bin/sh
rdate -s time.nist.gov
/sbin/hwclock --systohc
For me, I create /etc/cron.daily/rdate file directly using the following command:
cat > /etc/cron.daily/rdate << "EOF"
#!/bin/sh
rdate -s time.nist.gov
/sbin/hwclock --systohc
EOF

chmod +x /etc/cron.daily/rdate

Hope this helps ;)

Thanks.

Kindest regards,
Choon