Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Cron on Drupal 8 and Linux

By editor , 2 June, 2017
Question

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

Tags

  • Drupal 8
  • Code
  • Linux
  • Server
Virtualmin Tips

Comments

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer