One of our Linux VPS customers faced an issue wherein his Virtual Machine's system clock was running ahead of standard time.
To fix this, we set a cron job to sync the Virtual Machine's time with the WHM server using the rdate command.
Cron jobs are used to schedule commands to be executed periodically on Linux/ Unix-like machines. Cron job utility is quite useful, especially when you must run commands repeatedly at a specific time.
Following this tutorial, you will learn how to sync the time of your server with the WHM server using the crone job.
Before that, let us briefly understand the usage of the crone command.
Every cron command is broken into the following two parts –
[Schedule] [Command to be executed]
For Example: */20 * * * * /command/path
- In the above syntax, Command is the command you would like to execute at the scheduled time.
- The Schedule is a part that is further broken into five different options as follows –
- minute (0 - 59)
- hour (0 - 23)
- day of the month (1 - 31)
- month (1 - 12)
- day of the week (Sunday=0 to Saturday=7)
Set the crone job to sync the Virtual Machine's time with the WHM server.
To sync the Virtual Machine's system time with the WHM server time, you'll need to perform the following steps after logging into a Linux machine –
1. Connect to your Linux machine via SSH.
2. Edit/ Add crontab with the following command –
crontab -e // To add/update job in crontab
3. By issuing this command, a text editor will open where you can enter commands to be scheduled on a new line.
We added a command (at the bottom) to sync VM system time with WHM every hour (*/60), so this cron will run every hour and compare VM system time with rdate.cpanel.net. VM time will be synced with the WHM server time if any time difference is noticed.
#You can write a comment like this.
*/60 * * * * rdate -s rdate.cpanel.net