0

I have a shell script that executes drush sql-dump, compresses the result and then sends it to a backup server.

It works fine when run from the command line as root but it is failing silently and dispatching an empty file when run as part of a scheduled cron job.

This script has worked previously for me on another website as a cronjob and so I am somewhat confused what would be wrong now.

I work with Drupal 8.3.1 and Drush Version 8.1.11.

Any suggestions?

  • Add -v for verbose messages. Probably you're out of memory or you need to increase PHP time execution for drush. – kenorb Jun 8 '17 at 16:13
  • Why would the resource requirements be different for cron compared to doing it manually? – tanbog Jun 9 '17 at 1:42
1

After much frustration I have resolved the issue and will post the answer in case it is of use.

Cron seems to not always have access to the same PATH information as when a normal user - or even root - runs a drush command in a command line.

The solution came from comment #7 in this drush thread.

You need the path to drush. You can find this with the command:

which drush

In my case it was /usr/local/bin/drush

Then add the path info to the top of the shell script.

export PATH=$PATH:/usr/local/bin

And then it worked perfectly.

Additionally, it appears if your local mail is not set up correctly cron discards output from scripts which is why the drush: command not found error was not turning up in logs. To make sure you get logs from cron configure it for local mail. See this post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.