How to Automate Tasks on a Linux VPS Using Cron?

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 Virtual Machine's time with WHM server using 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 are required to run commands repeatedly on specific time.

Following this tutorial, you will learn how to sync time of your server with WHM server using crone job. Before that we will explain you the usage of crone command in brief.

Crone command


Every cron command is broken into following 2 parts.

[Schedule] [Command to be executed]
For Example: */20 * * * * /command/path

In above syntax, Command is the command you would like to execute on scheduled time. Schedule part is further broken into 5 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 crone job to sync Virtual Machine's time with WHM server


To sync 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 each on new line. We added command (at bottom) to sync VM system time with WHM every hour(*/60). This cron will run every hour and compare VM system time with rdate.cpanel.net. If any time difference is noticed, VM time will synced with the WHM server time.

    SHELL=/bin/bash
    HOME=/
    MAILTO=”mail@domain.com”
    #You can write comment like this.
    */60 * * * * rdate -s rdate.cpanel.net

  • 0 Users Found This Useful

Was this answer helpful?

Related Articles

Do You Provide TUN/TAP On VPS Hosting?

Typically, TUN/TAP is used when you want to utilize VPN services from your VPS. Windows VPS...

Will internal traffic between two VPS viz. a Database Server and a Web Server be counted in my bandwidth usage?

Yes it will. The traffic will be counted in the bandwidth usage of your VPS. Even if you use...

How to Upgrade PHP Version in cPanel/WHM Server?

Following article will assist you to upgrade PHP version in cPanel/WHM server. This article is...

How Do I Check Bandwidth Utilization of VPS?

Windows VPS To check/monitor usage of each Windows VPS, we have installed bandwidth meter tool...

Do You Offer VPS with 8 vCPU Cores?

No, we do not provide VPS with 8 vCPU cores. We provide VPS with maximum 4 vCPU cores. This is...