Setting up Cron Jobs in cPanel

Do you find yourself needing to automate certain commands or scripts within your site. Did you know cPanel provides a way to schedule these tasks to run at a specific time every day, week, month, etc.

What Is a Cron Job?

A cron job is simply a task that you schedule to run automatically at specific intervals. For example, if you want to back up a file every six hours, you can set this up easily using the cPanel Cron Jobs feature. Cron can run simple commands and programs written in languages such as PHP, Python and Perl.

Adding a Cron Job

Log into your cPanel and click Cron Jobs under ADVANCED

Before You Set up a Cron Job

The Cron Email section is where you enter an email address so the system can send notifications when your cron jobs run. It’s not necessary to set up an email.

The email notices can be a handy indicator that something is wrong, but if you have a lot of cron jobs or a single job that runs often, the emails can become a bit of an annoyance.

If you decide you would like to receive an email when your cron job runs, enter your email address in the Email field, and click the Update Email button.

Email

How to Set up a Cron Job

Scroll down to the Add New Cron Job section. Before configuring the individual time and date elements, check the Common Settings drop-down. Many times, you’ll find what you need there, and you can select the common setting to populate the time and date fields.

Common Settings

If the timing you need isn’t covered by a selection in the Common Settings drop-down, move down to the Minute, Hour, Day, Month, and Weekday settings.

You’ll see that each of these entries also have a Common Settings drop-down. Choose the appropriate settings.

NOTE: It is not necessary to enter a value into every field.

Settings Specification

The “Job” Part of the Cron Job

The last field in the Add New Cron Job section is Command. This is where you enter the path to the file containing the server command that will run at the times you just specified.

Enter the path and click the Add New Cron Job button.

As an example, you can use the following command to run a PHP script located in your public_html directory at the times you specified above.

php -f /home/YOUR_CPANEL_USERNAME/public_html/file.php

You’ll want to insert your actual cPanel username instead of YOUR_CPANEL_USERNAME

Add New Cron Job

When your cron job has been set up, you will see a success message.

Edit or Delete a Cron Job

Scroll down to the Current Cron Jobs section.

Click the Edit or Delete link. Edit will bring up the cron job settings.

Edit

Make any necessary changes and click the Edit Line button.

Delete will open a delete dialog.

Delete

Click the Delete button to confirm the deletion of the selected cron job.

Delete Confirmation

That’s All There Is to It

As you’ve seen, setting up cron jobs in cPanel is pretty straightforward. If you find them useful, you will no doubt think of other uses.