sql-dump failing when run as cron 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?
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.