Creating a CRON Job in the Task Scheduler

CRON tasks are automated jobs scheduled to run in Unix-based operating systems. Cron is a program used for planning and executing specific tasks at defined intervals, such as every minute, every hour, daily, etc.

You can set up a CRON job in cPanel under the Cron Jobs section.

There, you have the option to set the time for the task to run and specify the command.

To execute any file on the account through a CRON job, you can use one of two methods. You can execute a CRON job using a browser link to the file (Method 1) or by utilizing a selected PHP version along with the file path from the user account (Method 2).

Method 1:

To use a CRON job that triggers a script via a link, use the following command:

wget -q -O /dev/null [address] > /dev/null 2>&1

The -O option allows specifying the path for writing (using /dev/null ensures the file is not saved). The -q option prevents logging the operation. /dev/null 2>&1 redirects to the void, meaning no email notification will be sent about the CRON job execution. Replace [address] with the full link to the page to be called.

For regularly executed tasks, it is recommended to use > /dev/null 2>&1 to avoid filling the disk space with notifications.

Method 2:

To execute a CRON command through PHP, use the following command:

/opt/cpanel/ea-php74/root/usr/bin/php /home/username/file_to_execute > /dev/null 2>&1

In this case, provide the full path to the file and the PHP version to be used. In the example above, PHP version 7.4 is used.

Aleksandra Grygiel
Latest posts by Aleksandra Grygiel (see all)

Leave a Reply