The best way to run a Drupal 7 cron via drush

Edit 2015/4/8: You also want to read this article from Mattias on preventing cronjobs to overlap.

Edit 2015/3/18: Check this article on how to install drush via composer, which is currently the preferred way to install.

This is the best way to run your Drupal 7 drush cron command from crontab:

# Run cron every 15 minutes, quiet
*/15 * * * * drush --quiet --root=$HOME/htdocs --uri=http://www.example.org cron

# --quiet  means there is no output, so no mail every time cron runs
# --root   is a nicer way than first do a "cd $dir; drush cron"
# --uri    is needed so certain modules (like xmlsitemap and media)
#          don't generate urls like http://default/ but use the full
#          site url http://www.example.org

A more extensive cron with a custom SHELL, PATH and MAILTO would be:

# If there is output, mail it to this address
MAILTO=user@example.org

# Add more paths
PATH=$PATH:$HOME/.extra/bin

# Make sure we are using bash as shell (or any other shell)
SHELL=/bin/bash

# Run cron every 15 minutes, quiet
*/15 * * * * drush --quiet --root=$HOME/htdocs --uri=http://www.example.org cron

# Run an import every night, output goes to MAILTO
0 2 * * * drush --root=$HOME/htdocs --uri=http://www.example.org run-import

That’s all.

comments powered by Disqus