Understanding Cron Jobs
When running a complex website, it makes sense to have a way of automating regular tasks, so you never have to remind yourself to do them. This is what Cron Jobs are for—Linux commands that schedule tasks. With a good knowledge of Linux commands, you can make the best use of these Cron Jobs.
A Cron Job can be quite handy, as it can be instructed to run in hourly or minutely increments, on a certain day every week or on specific dates every month—you can even mix and match these settings. However, be advised that running too many Cron Jobs too often can lead to undue stress on the servers. Such limits may not apply to non-shared resources like a dedicated server.
These Cron Jobs can be used for routine storage housekeeping or for more advanced task flows that free up time for more immediate concerns. There are even scripts that depend on Cron Jobs to run. The good news is that such scripts will clearly detail what needs to be done concerning the Cron Job.
How Cron Jobs Work
A Cron Job consists of three parts:
- A script that is meant to run.
- A command (specified in cPanel) that runs the script at set intervals or at specific times.
- An action or result generated by the script, depending on its nature.
Adding Cron Jobs via cPanel
Once you’re logged in, under the ‘Advanced’ section in cPanel, select ‘Cron Jobs’ or type ‘Cron Jobs’ in the top right search bar.
In the next section, select ‘Cron Email’ if you wish to receive a report email every time the Cron Job runs. Then enter or confirm your existing, working email address (by default, it uses the cPanel user email address).
2.In ‘Add New Cron Job’ > ‘Common Settings’, ensure that all settings meet your requirements. You can choose specific time parameters for your Cron to run—from month all the way to minute.In ‘Command’, enter the command that you’d like to run as a Cron Job.
3.That’s it! Just click ‘Add New Cron Job’, and it will be added.
In cPanel, you can also view all ‘Current Cron Jobs’. Under the ‘Action’ column, you can ‘Edit’ or ‘Delete’ any existing job.
cURL, GET, and WGET
Here’s some good news when it comes to these request commands: as common as they are in Cron Jobs, there are no additional steps needed to access them; they’re all enabled by default with us.
Things to Keep in Mind for Running Cron Jobs
- Any such process will initially use the home directory to run.
- Since Cron processes do not generate an interactive command line, startup files like
.bashrc
will not be accessed. - If you name an executable file without a full path—either absolute or relative—the process will expect it to be in the
/bin
and/usr/bin
paths only. - For any script, the interpreter’s location can be provided in one of two ways: with a full path in a proper
#!
format or in the shell interface. - All file locations must have full paths—absolute or relative.