View Categories

How to manage the Cron Jobs in cPanel

6 min read

Introduction #

Cron Jobs” is a feature of cPanel that allows you to configure a script for automatic execution for an indefinite period of time. This feature is particularly useful if your website has to perform some automated tasks on a regular basis. Such is the case with most of the Opensource applications used as platforms for building websites. In the next lines of this tutorial, we will show you how to add a new Cron Job and how to manage any already configured such.

Accessing the Cron Jobs feature in cPanel #

As we have mentioned, “Cron Jobs” is a feature of cPanel and to be able to use it you will have to be logged into the cPanel service. Then you will see a complete list of all the features cPanel has to offer. To access the “Cron Jobs” feature, you can either use the search tool provided at the top of the page, or you can look for the “Advanced” features group and within that group, you will see the “Cron Jobs” feature.

Accessing the Cron Jobs feature in cPanel

Clicking on the feature will take you to the default page of the same. There you will find a brief explanation of what the “Cron Jobs” feature is and also all other tools you will need to manage the “Cron Jobs” of your Web Hosting Account. 

Configuring Cron Email #

By default, the output of the execution for each Cron Job will be sent as an email to the default email address for your Web Hosting Account. If you would like to receive the output on another email account, you will need to configure it in the “Cron Email” section. There, by inputting the email address into the “Email” field and then by pressing the “Update Email” button you will be able to set a new email address for receiving the output from the Cron Jobs executions. 

Configuring Cron Email

We strongly recommend when configuring the Cron Email to set an email account associated with your Web Hosting Account. You can create a new email account by following our tutorial “How to completely manage Email accounts in cPanel?”. 

Another thing you should consider is that you can completely disable the emailing of the output from your Cron Jobs execution. To do that, you will need to add the following string at the end of the Command for your Cron Job:

>/dev/null 2>&1

or for example, if the command you would like to execute on a regular basis is:

/usr/local/bin/php /home/hostarma/public_html/script.php 

Then after you add the above mentioned sting at the end the complete command will become:

/usr/local/bin/php /home/hostarma/public_html/script.php >/dev/null 2>&1

As you can see disabling Cron Job output is relatively simple. Now let’s add a new Cron Job.

Adding a new Cron Job #

To add a new Cron Job, you will have to scroll down a bit and right after the “Cron Email” section, you will find the “Add New Cron Job” section. There you will be able to fully configure the script you will need to be executed regularly. Let’s review the settings you will have to configure:

  • Common Settings – Under this field, you will find common command execution intervals for executing the command such as “Once per minute”, “Once per five minutes”, “Twice per hour”, “Once per hour” and so on. 
  • Minute– Here you will be able to configure the minute this command will be executed at. You can also set a common setting like “Once per minute”, “Once per two minutes”, “Once per five minutes” and so on. 
  • Hour – In this field, you will be able to specify the hour your command will be executed. You can either specify concrete hours or choose from the common settings options like “Every Hour”, “Every Other Hour”, “Every Third Hour” and so on.
  • Day – Here you will be able to specify the exact day from the month you would like this command executed in. 
  • Month – Here you will be able to specify the concrete month you would like the command the be executed in.
  • Weekday – Here you will be able to specify the concrete Weekday in which you would like this command executed. 
  • Command – Here you will need to specify the actual command you would like to have executed. 

Once you are ready with the configuration please click on the “Add New Cron Job” button so you can save the configured command. 

Adding a new Cron Job

We recommend configuring a Cron Job for a period not shorter than “Once per five minutes */5 * * * *” or otherwise, depending on the executed command you risk overloading your Web Hosting Account.

Depending on the type of script you would like to execute or more precisely on the used programming language, you will have to configure different commands. For example, if the executed script is PHP based, you will need to add the path to the PHP binary before the path to the executed script:

/usr/local/bin/php 

Here are the paths to the other typically used binaries:

  • Bash – /usr/bin/bash
  • Perl – /usr/bin/perl
  • Node.js – /usr/local/bin/node
  • Python – /usr/bin/python2.7

Please note that executing crons for virtual environments is not an available option. 

We always advise testing the command first before adding it as a Cron Job. To do that you will simply need to login over the SSH service for your account and simply paste the whole command in order to review the command’s output and the execution.

Managing Existing Cron Jobs #

Once added, the Cron Job will be listed in the next section called “Current Cron Jobs“. There you will be able to further manage your existing Cron Jobs. 

To Edit an existing Cron Job, please click on the “Edit” link next to every Cron Job on the list. This will bring up an editing interface that is the same as the one you have used when adding the Cron Job, however this time with values already configured. 

Edit Cron Job

Once you are done editing the Cron Job, please click on the “Edit Line” button at the bottom of the editing interface.

To Delete an existing Cron Job, please click on the “Delete” link next to the “Edit” link for every Cron Job on the list. This will bring up a confirmation which after confirmed will remove the Cron Job you have chosen. 

Delete Existing Cron Job

As you can see adding new Cron Jobs or managing existing ones is not a hard task. Still, if you need any further information on the matter or in case you are facing some sort of difficulty adding new Cron Jobs, please do not hesitate to submit a support ticket and check with our experienced Technical Support Crew since they will be able to assist you with every Cron related issue. 

Powered by BetterDocs