PrackHost : Hosting Premium Web LiteSpeed

Cron tasks

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.

1. We accede to Cron Tasks

In order to manage our tasks cron we will go to the access of Cpanel €“ Cron Tasks

We accede to Cron Tasks in cPanel

2. E-mail

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.

E-mail to receive details of the executed tasks cron

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€: €œ3.4.6.0€ (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.

To add Cron tasks in cPanel

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.

To deactivate warnings of execution of cron

Published in ,
Transformation for PrackHost

PrackHost

Hosting specialized in Joomla! , Wordpress, Prestashop and Moodle. Services of hosting in the cloud. Dedicated servers VPS and.

Categories