Scheduled tasks or cronjobs are process executions that happen automatically in the background. Generally speaking, a cronjob is a Linux utility that sets a command or command set at times or frequencies to perform specific tasks on any VPS.
Through cronjob you can automate specific tasks , such as automated email sending, automatic backups , clearing your server's cache, deleting temporary files, and ultimately whatever you have in mind. Some practical examples of the use of cron jobs: When you receive in your email at 7 AM advertising of a multi-store, when you receive a payment from the government or when the alarm of your mobile phone sounds.
The use of cronjobs today is not a theoretical novelty, but a utility that has supported technological development for years and is important to understand the algorithmic operation that occurs automatically.
How to install Cron Job on Linux?
To install this utility you must run the following command on your Debian / Ubuntu machine
apt install cron
The above command will install the utility, creating a file called crontab in the / etc / folder (/ etc / crontab)
How to edit Crontab in Linux?
To edit crontab in Debian / Ubuntu , you can use your favorite editor, in our case we will use nano
nano / etc / crontab
Which will open a file with sample syntax like the following:
A basic example of using crontab, to run a URL at 7 AM
0 7 * * * curl https: // mox.cl
In which case, at 7AM you run the CURL function to call the website in question (the asterisk represents any number or, in this example, any day)
Another basic example, to reset the RAM of your Debian / Ubuntu virtual machine, it can be like this:
0 * * * * free -m
Without a doubt, the execution of cronjob will facilitate the operation of any task that can be automated safely (since it occurs within your VPS). You can run tasks from commands directly on your server or run scripts that you have made in another programming language. In addition to executions on your own virtual server, you will be able to execute tasks externally using CURL or WGET.
When you use a Hosting with cPanel, you will be able to manage these commands in a more friendly way through the Cron Jobs module available in cPanel. Or, if you use a VPS with cPanel or DirectAdmin, there are platforms with templates that will allow you to carry out these tasks.
When you use a CMS such as Prestashop or Wordpress, you can directly install a module that allows you to use these tasks automatically, such as the generation and cleaning of caches.