When running a large website, it makes sense to have a mechanism to automate routine chores so that you don’t have to remember to do them. Cron Jobs – Linux commands that schedule tasks – are used for this. That means that if you have a strong understanding of Linux commands, you can get the most out of these Cron Jobs.
A Cron Job is useful because it may be set to run in hourly or minutely intervals, on a specific day each week or on a specific date each month – you can even mix and match these options. However, running too many Cron Jobs too frequently can cause the servers to get overworked. Non-shared resources, such as a dedicated server, may be exempt from such restrictions.
These Cron Jobs can be used for basic storage maintenance or for more complex job flows that free up time for more pressing issues. Cron Jobs are even required for the execution of scripts. The good news is that such scripts will make it very clear what needs to be done in relation to the Cron Job.
How Cron Jobs Work
A Cron Job is made of three parts:
- A script that is meant to run
- A command (specified in cPanel) that runs the script at set intervals or at set times.
- An action or result generated by the script, as the nature of the script might be.
Using cPanel to add Cron Jobs
1- Select ‘Cron Jobs’ under ‘Advanced’ in cPanel or type ‘Cron Jobs’ in the top right Search bar once you’ve logged in.
2- Select ‘Cron Email’ for the following section if you want a report email every time the cron job starts. After that, enter or confirm your current, active email address (by default it uses the cPanel user email address).
3- In ‘Add New Cron Job’ > ‘Common Settings’, ensure that all settings meet your requirements
4- You can set specified time limits for your Cron to run, ranging from a month to a minute.
5- In the ‘Command’ field, type the command you want to run as a Cron Job.
6- That’s all there is to it. Simply select ‘Add New Cron Job’ to add it.
You can also examine all ‘Current Cron Jobs’ in cPanel, where you may ‘Edit’ or even ‘Delete’ any existing job by going to the ‘Action’ column.
cURL, GET, and WGET
When it comes to these request commands, there’s some good news. There are no further steps required to access these, as they are ubiquitous in Cron Jobs, and they are all enabled by default with us.
Things to Remember When Running Cron Jobs
1- Any such process will begin by running in the home directory.
2- Startup files such as bashrc will not be accessed since Cron processes do not generate an interactive command line.
3- If we name an executable file without a full path – absolute or relative – the process will assume it is in the ‘bin’ and ‘usr/bin’ directories alone.
4- The interpreter’s location can be specified in one of two ways for any script: a full path in appropriate #! format or using the shell interface.
5- Full paths must be used for all file locations, whether absolute or relative.
Leave A Comment