Verpex Knowledge Base

Get all the help you need here.

Understanding Cron Jobs

Posted 14th February, 2022

When running a complex website, it makes sense to have a way of automating regular tasks, and never have to remind yourself to do them. This is what Cron Jobs are for – Linux commands that schedule things. And that means, that armed 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 date every month - you can even mix and match these. Be advised, though, that running too many Cron Jobs too often can lead to undue stress on the servers. However, such limits may not be applicable to non-shared resources like a dedicated server.

These Cron Jobs can be used for good old storage housekeeping, or for more advanced task flows that can free up time for more immediate concerns. There are even scripts that depend on Cron Jobs to run. The good thing is that such scripts will clearly detail what needs to be done with regards to the Cron Job.

How Cron Jobs Work

A Cron Job is made of three parts:

  1. A script that is meant to run

  2. A command (specified in cPanel) that runs the script at set intervals or at set times.

  3. An action or result generated by the script, as the nature of the script might be.

Adding Cron Jobs via cPanel

1- Once you’re logged in, under ‘Advanced’ in cPanel, select ‘Cron Jobs’ or type in ‘Cron Jobs’ on the top right Search bar.

Understanding Cron Jobs1

2- For the next section, pick ‘Cron Email’, if you wish to get 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).

Understanding Cron Jobs2

3- In ‘Add New Cron Job’ > ‘Common Settings’, ensure that all settings meet your requirements

Understanding Cron Jobs3

4- You can choose specific time parameters for your Cron to run – from month all the way to minute.

5- n ‘Command’, enter the command that you’d like to run as a Cron Job.

6- That’s it. Just ‘Add New Cron Job’, and it will be added.

Here in cPanel, you can also view all ‘Current Cron Jobs’ where, under the ‘Action’ column, you also get to ‘Edit’ or even ‘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.

To Keep in Mind for Running Cron Jobs

1- Any such process will initially use the home directory to run.

2- Since Cron processes do not generate an interactive command line, startup files like bashrc will not be accessed.

3- If we 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 alone.

4- For any script, the interpreter’s location can be provided in one of two ways - a full path in a proper #! format or in the shell interface.

5- All file locations must have full paths – absolute or relative, again.

Categories:Databases
Jivo Live Chat