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= 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

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

# If there is output, mail it to this address

# Add more paths

# Make sure we are using bash as shell (or any other shell)

# Run cron every 15 minutes, quiet
*/15 * * * * drush --quiet --root=$HOME/htdocs --uri= cron

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

That’s all.

comments powered by Disqus