How to use cron system on linux and drupal 8 ?
Run cron by drush
drush cron
Add cron hook to a custom module.
/**
* Implement hook_cron()
*/
function MYMODULE_cron() {
// Your codes.
}
Add Drush command by linux cron tab.
0 * * * * PATH_TO_DRUSH -r PATH_TO_DRUPAL DRUSH_COMMAND
Example:
0 * * * * /usr/bin/drush -r /path/to/drupal cr
* * * * * /usr/local/bin/drush -r /home/me/public_html/drupal8 cron >/dev/null 2>&1
Run php script by linux cron tab.
0 * * * * /usr/bin/php -f /home/me/my_script.php >/dev/null 2>&1
Disable cron job output (Remove logger out)
To disable logger output, just add >/dev/null 2>&1 et the end of the command.
Like:
CRON_CONFIG COMMAND >/dev/null 2>&1
Example:
0 * * * * /usr/bin/php -f /home/me/my_script.php >/dev/null 2>&1
* * * * * /usr/local/bin/drush -r /home/me/public_html/drupal8 cron >/dev/null 2>&1
Create cron job on using Virtualmin / Webmin. (Scheduled Cron Jobs)
Goto:
Webmin -> System -> Scheduled Cron Jobs -> Create New Cron Job
Add command like (Example)
PATH_TO_DRUSH -r PATH_TO_DRUPAL DRUSH_COMMAND
Ex:
/usr/bin/drush -r /path/to/drupal cr
Ex:
/usr/local/bin/drush -r /home/me/public_html/drupal8 cron >/dev/null 2>&1
Configure schedule and other settings.
Create / Save the cron job
Run a shell script by cron from a selected folder
## Examples:
cd /home/drupal/public_html/drupal8; ./scripts/myscript.sh
cd /home/drupal/public_html/drupal8; ./scripts/myscript.sh [ARGUMENTS]
cd /home/drupal/public_html/drupal8; ./scripts/myscript.sh [ARGUMENTS] >/dev/null 2>&1
Comments