1

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?

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

1 Answer 1

3

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.

1
  • This finally fixed things for me, even though I had already thought to spell out /usr/local/bin/drush and /usr/bin/gzip in full in my bash script. (slightly odd setup, backing up on a Mac Mini being used as a production server…) Commented Apr 7, 2020 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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