Cron is a time-based job scheduling program in Linux (and other UNIX-type operating systems) that is used to automate repetitive tasks on a server. Using cron jobs in cPanel helps you by automating the process.
A cron job is scheduled to run at specific times or dates. The “job” is usually a script that performs some sort of updating task. Expiring or deleting user accounts, sending out automated email, updating tables or other data visualization from a database are just some examples.
Many website updates and maintenance tasks can be automated with cron jobs.
The format for a cron job can seem a little complicated the first time you go through it, but we’ll break it down into easily understandable parts. Cron jobs are a powerful tool, and they can save you a lot of time and trouble.
In this tutorial, I’ll show you how to set up cron jobs in cPanel.
Let’s get started.
Finding the Cron Job Controls in cPanel
Log in to cPanel.
In the “Advanced” section, click the “Cron Jobs” link or icon.
The first thing you may notice is a big warning box telling you that “You need to have a good knowledge of Linux commands before you can use cron jobs effectively.”
It’s true that a good knowledge of many things will help you use them more effectively. It’s also possible to be quite effective with just a bit of knowledge and the ability to copy examples.
Once you see how a cron job is configured, you’ll be able to translate that knowledge to a number of different uses.
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. For example, “Why haven’t I received a cron email in the past week?”. 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 want to receive an email when your cron job runs, enter your email address in the “Email” field, and click the “Update Email” button.
Note that in some cases the default address for your domain may be automatically set to receive cron job notices (see the image below). If you do not want to receive notices, click the “Update Email” button while leaving the “Email” field empty.
How to Set up a Cron Job in cPanel
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.
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.
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.
If you want to execute a php script, the command consists of two parts: the path to php for your account, followed by the path to the file you want to execute.
When your cron job has been set up, you will see a success message.
To 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. Make any necessary changes and click the “Edit Line” button.
“Delete” will open a delete dialog. Click the “Delete” button.
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 applications for cron jobs.
It’s important to remember though, that the script your cron job triggers can run commands on the server. So the same cautions that you would take when working on the command line should be taken when triggering a script with a cron job.
Have you ever set up cron jobs using cPanel? Can you think of any manual update or maintenance tasks you perform that could be done for you by a cron job?