This is an odd one. I thought I would try using drush to do the cron jobs for a couple of drupal sites.

If I run the command interactively from the shell, then "drush @sitealias cron" work brilliantly.

But a crontab entry like this:

0 0 * * * drush @sitealias cron

results in an error:

put: No value for $TERM and no -T specified
The directory {A valid drupal Root} does not contain a valid Drupal [error] installation
Command cron needs a higher bootstrap level to run - you will need [error] invoke drush from a more functional Drupal environment to run this command.
The drush command 'cron' could not be executed. [error].

Doing a redirect of standard out/standard error [append with > /dev/null 2>&1] obviously gets rid of the error message, but doesn't fix the problem.

It's not really a big deal, as there are other ways of successfully running Drupal's cron. I think this is a problem with my shell environment rather than a drush problem. Anyone else seen something like this?

Comments

greg.1.anderson’s picture

This is expected behavior. There are a couple of things going on. First, cron runs in a clean environment. You'll probably want to use /bin/env PATH=... drush @alias cron to insure that your PATH is set. Also, make sure that cron is running as the same user that you're using when you run drush from the shell. If your aliases are in $HOME, then drush won't find them if you run it as another user.

I think I've seen the $TERM thing before, but don't know the solution off the top of my head. Try man bash.

For my part, my crontabs have looked like this since before I started using drush:

3 2 * * * /usr/bin/wget --no-check-certificate -O - -q -t 1 http://greenknowe.org/cron.php

That works pretty well, so I haven't switched to using drush from cron. It should work just fine if you set up your environment.

greg.1.anderson’s picture

Status: Active » Fixed

#715480: Can't run drush from cron talks about the need to set up environment variables from cron. #740448: tput errors when running "drush" script in cron reportedly fixes the problem you're having with $TERM.

Re-open if you have continuing problems related to drush.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.