Cron is a feature of Linux that you can use to run specific website tasks at scheduled times. These tasks are referred to as “cron jobs” and function to automatically execute commands and run scripts.
Using the cPanel interface makes simplifies cron job setup. Although you do need a working knowledge of Linux commands, the process itself is straightforward. A successful cron job requires:
- A web host running a Unix installation such as Linux
- A script to reference and execute
- The command that tells the script to run on your set schedule
- The action or output of that script
What are Cron Jobs For?
You can set up cron jobs in cPanel to do any number of things such as send out scheduled email notifications, clean up unused or temporary files, update tables that summarize changing data, auto-check for broken links on your site, or deactivate expired accounts in a members-only section.
Certain website functions and addons require cron jobs to run scripts. In these cases, you’ll be given instructions on which commands to use and how to create the cron jobs for the necessary functions.
Setting Up a Cron Job
To get started with a cron job in cPanel, log in to the dashboard and scroll down to the “Advanced” section. Click on the Cron Jobs icon, which looks like a calendar with a clock in front of it.
This brings you to the cron jobs page where you can specify a cron email, add a new cron job or modify existing cron jobs.
If you want cPanel to send you an email notification each time a cron job runs, you need to input a working email address. To do this, click on “more” under Cron Email.
Input your desired email address and click “Update Email” to save it.
Adding a New Cron Job
Underneath the email settings box, you’ll see the area to Add a New Cron Job.
The Common Settings dropdown contains some of the time schedules most often used for cron jobs, including every minute or hour, every day or week, twice a month, once a month and once a year. You can choose one of these settings or create your own custom schedule with the Minute, Hour, Day, Month and Weekday boxes.
The last thing you need to do is enter the command to execute the script for the cron job. This is where the knowledge of Linux commands comes in. It may be a command that you were given by a specific application or one for a cron job that you’re setting up yourself. Either way, the command specifies the path there the script files are stored and is responsible for running that script on schedule.
Once you’ve entered your command, a green checkmark should appear next to the Command box to indicate that the code is valid. Click “Add New Cron Job” to complete setup.
Managing Cron Jobs
To modify or delete existing cron jobs, navigate to the cron jobs area and scroll down to “Current Cron Jobs.”
Click the Edit link next to the cron job you wish to change. You can then update the timing or the command as necessary. Hit the “Edit Line” button to confirm the changes.
If a cron job is no longer needed, click the Delete link next to it and then click the “Delete” button when asked if you’re sure.
These steps help you to manage complex processes on your website without having to invest a lot of time in manually updating files or executing changes.