How to program tasks automated in cPanel
The Cron tasks allow to automate certain commandos or sequences of commandos in the account of cPanel of your lodging Web.
You can define that a commando or a sequence of commandos executes themselves to one hour determined within a specified interval.
For example, you could form programmed tasks and eliminate the temporary files weekly to release disc space.
Or for example, if we managed a Web of sport events.
We could execute script the days of the parties so that our Web is connected to other than it offers a service of update of the markers in real time and thus be able to practically offer the results in our Web in direct.
In Linux servers these tasks denominate crontab.
Index of this article
1. We accede to Cron Tasks
In order to manage our tasks cron we will go to the access of Cpanel Cron Tasks
Following the example of the sport Web, we are going to suppose that we have script called marcadores.php .
We wish to execute every 5 minutes between the 17 and 24 hours the following days: Wednesday, Thursday, Saturdays and Sundays.
In the first section Cron E-mail we will see a section to introduce our email. cPanel will use it to send an email to us whenever script is executed.
This can serve to us to verify that the system carries out the work suitably.
But once verified he is better to deactivate this option since the mailbox of our email could fill suddenly and collapse it.
More ahead we will see as avoiding to receive these notifications.
3. To add a new Cron task
In the following section To add a new Cron task it is where we will indicate to cPanel the moment at which we wished is executed our new script (day of the month or day of the week).
We observe that first the drop-down one contains common Configurations that we can use in simple cases.
For example some configurations come type: every second, hourly (hourly), newspaper (daily), weekly (weekly), monthly (monthly) or annual (yearly or annually).
It is extremely easy to insert the values adapted in the fields MINUTE, HOUR, DAY, MONTH AND DAY OF WEEK, being unfolded the common Configurations and selecting the option that adjusts more to our needs.
But our example is something more complex, we see its executions:
- Every 5 minutes: this is simple. According to the drop-down one we must introduce in the field MINUTE: */5
- Between the 17 and 24 hours. In this case we must insert in HOUR the following thing: */17,18,19,20,21,22,23,0
- Daily (more ahead we will say what days to him exactly). We introduce in DAY the following thing: *
- Every month: in this case we will only have to insert: *
- Wednesdays, Thursday, Saturdays and Sundays. In this case we will introduce in the field DAY OF WEEK: 18.104.22.168 (of Monday to Sunday: 0-6 being 0 Sunday).
Well, up to here already we have our organized calendar. So that ours script is executed Wednesdays, Thursday, Saturdays and Sundays, every 5 minutes. Home from the 5 in the afternoon to the 12 at night. To only the appropriate instruction remains us to introduce in the line Commando that cPanel executes ours script.
We are going to suppose that we have the file marcadores.php (nuesto script) installed in our Web Joomla! in the directory cron. Therefore the sentence to insert would be the following one:
php - f /home/mi-usuario-cpanel/public_html/crontab/marcadores.php
(without forgetting to replace my-usario-cpanel by real ours usario).
We must consider that there is to put the real route regarding our Control Panel where script or file that we want to execute is located.
In this case he is within the folder public_html that are the root of ours hosting and the folder crontab.
According to where our file is located this route will change.
Now we punctured in the button To add new task of Cron and will see underneath present Cron Tasks that it is had including our new task.
With this last option, the file crontab of cPanel will have been formed.
4. To deactivate warnings of execution
Once we have verified the correct operation, we can deactivate the option of the shipment by email of the confirmation that sends cPanel whenever the file is executed.
For it we punctured in Publishing to the right of our task and in the section present Tasks of Cron. The task unfolds and in the section Commando we add to the phrase >/dev/null in the end 2>&1 , being our commando as it follows:
php - f /home/mi-usuario-cpanel/public_html/crontab/marcadores.php >/dev/null 2>&1
(without forgetting to replace my-usario-cpanel by real ours usario)
Of this form, they will be executed, but we will not receive notifications in our email address.
The ideal will be to receive the notifications to verify that it is being executed, but this will depend on the regularity that we give the automated work since if the execution frequency is very high we will receive many notifications in our mailbox of mail.