What is a cron job?
Date:
Mon, 25 Jul 2022 12:09:35 +0000
Description:
Make this time-based job scheduler do all tedious administrative tasks for you
FULL STORY ======================================================================
If youre having a hard time remembering to run a script regularly or you simply wish to invest your time and energy into something a bit more
creative, its high time to put cron to good use.
However, before diving in youll probably want to know what cron is, what exactly a cron job is, and what it can do for you.
Cron is a time-based task scheduler in Unix-like operating systems (OS) and its one of the most useful utilities youll find there. Created in AT&T Bell Laboratories in 1975 and named after Chronos, a Greek personification of
time, cron didnt only come a long way from its initial inception but managed to remain relevant to this day.
Hostinger "free website" hosting offer: $41.88 $0
TechRadar Pro exclusive : Get everything you need to put your business
online with a WordPress friendly hosting package that comes with 30GB of storage and 100GB bandwidth. Grab a full refund of $41.88/41.88 in Amazon vouchers when you purchase Hostingers single shared hosting package. Terms
and conditions apply . *Initial purchase required View Deal
Its commonly used for automating tasks that run in the background at specific times such as scheduled backups, monitoring disk space, managing system maintenance tasks, freeing drive space from useless files, sending bulk emails, and much more. All these different scheduled tasks (or jobs) are
known as cron jobs.
To help you get started with cron jobs well learn how you can set it up using cPanel , Plesk, and WordPress. However, before that, lets find out a bit more about how a cron job works. What is cron job used for?
Cron is essentially a daemon (a computer program that runs as a background process serving various purposes) that detects and executes cron jobs at specified dates and times whether its a one-time or recurring task. It runs every minute during which it inspects a set of pre-defined directories in
your file system to determine whether cron jobs require to be run.
To run a cron job, three components need to be present including a specific command or a script thats to be executed, a command that executes the script on a specific time basis (usually set in your control panel), and an action
or an output of the script that would depend on whats the script in question does.
Cron jobs can be scheduled to run multiple times a day or to run at specific hours and minutes on specific days and months. To do this youll be using crontabs, which is a list of commands OS uses to let you schedule all sorts
of tasks thatll be executed by cron expressions at the pre-set timing.
We should note that most scripts that use a cron job will come with specific how-tos, so youll know what needs to be set up and how. How to set up a cron job using cPanel
cPanel is the most popular Linux-based graphical user interface (GUI) out there and it will simplify the tedious tasks of managing and monitoring all aspects of your website or websites. So, if you have the pleasure of
utilizing this user-friendly control panel, this is how you can set up a cron job with it.
First, lets get started by logging into your cPanel. Once youre in the cPanel dashboard, scroll down to the Advanced section, search for Cron Jobs and
click on the icon.
This will take you to the cron job interface where you can input your e-mail address so that the cron utility can send you e-mails every time one of the cron jobs produces an output its a simple way to keep track of every job and review potential errors.
After this, youll want to scroll down to the Common Settings section and configure specifications about the cron jobs you want to add. Here you can pick the schedule you want a cron job to run on once per minute, once per five minutes, once per hour, and so forth.
Once the schedule is chosen, the text box below will be filled out automatically, but you can alter it to match your needs.
At last, enter the command you want the system to run in the Command section, tap into Add New Cron Job and congratulations, youve set up a cron job. How
to set up a cron job using Plesk
Plesk is a web hosting platform with a control panel that allows the administrator to set up websites, email accounts, DNS , and databases through a web browser.
While Plesk and cPanel serve the same purpose, they differ when it comes to GUI and the servers they support. cPanels intuitive interface is more user-friendly but the web-based control panel is compatible with Linux
servers only. On the other hand, Plesk supports both Windows and Linux servers.
Much the same as with cPanel, to set up a cron job using Plesk youll need to log in and click on the Scheduled Tasks button on the right section of the dashboard.
There youll see an option to add, remove, and refresh tasks, but also a Setting section youll want to visit first and set a correct time zone. After this, click on Add Task and add any specification about the cron job you want to run including time intervals, notifications, a description, and enter the actual command. Thats it, the cron job has been set up.
The only slight difference between setting cron jobs using cPanel and Plesk
is that with the latter one the icon doesnt say cron jobs. How to set up a WordPress cron job
If you want to set up a cron job for your WordPress website , the first step is to install and activate one of the cron job plugins (such as WP Crontrol, Easycron, and Advanced Cron Manager), which youll find inside the WordPress.org plugin library. This is part of WordPress own cron system which enables it to set and perform all sorts of scheduled tasks.
The easiest way to do this is to open your WordPress dashboard, go to Plugins and click on Add New. Once you find the cron job plugin you wish to use,
click on Install Now, wait for a couple of seconds for the installation to be finished, and then tap into Activate.
We advise using WP Crontrol plugin since its the simplest one to use and not likely to confuse less experienced users its also free.
Once this plugin is set up and activated you can go to Tools where youll now see Cron Events and Scheduled Actions buttons, so lets click on the first
one. Itll open a new section where you can view your active cron events and schedules, as well as add new ones.
To add a new event youll need to tap into Add Cron Event, input a hook name, add optional arguments (using the JSON encoded array), choose time intervals, and then click on Add Event. Alternatively, you can go to Add PHP Cron Event and add your PHP code, after which everything works the same as in the previous example. What are the benefits of a cron job?
An ability to set up automatically scheduled jobs is not only a time-saver
but also a superb way to make sure you dont forget about critical tasks.
Also, using cron jobs will give you complete control over what jobs are running, since you can choose the exact time theyll be executed.
For instance, if youre running a membership site where accounts come with expiration dates, you can utilize cron jobs to deactivate or delete expired accounts at regular intervals which will give you some time off to focus on more important tasks.
Also, since cron jobs arent occupying memory in your system when theyre not running, there wont be any unexpected slowdowns. If a cron job fails to run
at the scheduled time for whatever reason, it will automatically start again when the next scheduled interval comes. Choosing a cron job
Cron jobs are extremely effective in automating repetitive tasks and setting them up isnt too complicated regardless of whether youre using cPanel, Plesk, or WordPress.
So, now that youve set up your first cron job its time for you to take a
break while letting it do all those tedious tasks for you. Want to build a site? Choose from the best website builder services on the market
======================================================================
Link to news story:
https://www.techradar.com/news/what-is-a-cron-job/
--- Mystic BBS v1.12 A47 (Linux/64)
* Origin: tqwNet Technology News (1337:1/100)