My goal is to pipe mail with Postfix into a drush command. I made a simple bash script that redirects stdin to the drush command, and I configured Postfix to pipe mail to the script. But executing drush from the script does not work, as it cannot connect to the database. I assume there is some environment/bootstrapping missing but I cannot figure out what.
#!/bin/bash # Enter Drush environment cd `dirname $0` # Redirect stdin to Drush command, log any ouput /usr/local/bin/drush my-command <&0 &> my_command.log
Running the script from terminal works fine:
$ ./postfix-filter.sh < test.eml
But when triggered by Postfix receiving a mail, the following is printed to the log file:
The drush command 'inmail-process' could not be found. Run `drush [error] cache-clear drush` to clear the commandfile cache if you have installed new extensions. Drush was not able to start (bootstrap) the Drupal database. [error] Hint: This may occur when Drush is trying to: * bootstrap a site that has not been installed or does not have a configured database. In this case you can select another site with a working database setup by specifying the URI to use with the --uri parameter on the command line. See `drush topic docs-aliases` for details. * connect the database through a socket. The socket file may be wrong or the php-cli may have no access to it in a jailed shell. See http://drupal.org/node/1428638 for details. Drush was attempting to connect to: Drupal version : 8.0.0-dev Site URI : http://default Database driver : mysql Database hostname : 127.0.0.1 Database port : Database username : root Database name : drupal PHP executable : /usr/bin/php PHP configuration : /etc/php.ini PHP OS : Darwin Drush version : 7.0-dev Drush temp : /tmp directory Drush configuration : Drush alias files : /Users/mdi/.drush/aliases.drushrc.php Drupal root : /usr/local/var/www/d8/www Site path : sites/default Active config path : sites/default/files/config_FTG0_Sy-OJ0Mco 1c4ZlOBwJ3Ia-sMX0PcQiIiaGcsRufMWfFBWwSWLu lhB83nL0hF9Dl9Y24-w/active Staging config path : sites/default/files/config_FTG0_Sy-OJ0Mco 1c4ZlOBwJ3Ia-sMX0PcQiIiaGcsRufMWfFBWwSWLu lhB83nL0hF9Dl9Y24-w/staging
As you can see from the output, I have already tried setting the database host to 127.0.0.1, as suggested by various discussions I found.
Any ideas on what is missing?