0

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.

Bash script, postfix-filter.sh:

#!/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?

4
  • 1
    Comment, as I'm only guessing at this stage. "The drush command 'inmail-process' could not be found." is because you are executing the drush command from a directory where it can't find an appropriate drupal install. The nice way to solve that is to set up a drush alias. The "quick hack" way would be to cd into the right sites/ dir before running drush, so it can find the settings.php file.
    – Letharion
    Nov 5, 2014 at 8:24
  • @Letharion, yeah, that's the first line in the script ;)
    – Arla
    Nov 5, 2014 at 8:40
  • 1
    I can see there's a cd in there, but I don't know what that does since your shell script isn't invoked with -x :) So I still think that's the issue. What do you get if you do "drush sql-connect" in the same script? Dont post the output verbatim, as it will include sensitive info.
    – Letharion
    Nov 5, 2014 at 8:44
  • Sorry, I misread your first comment. Thanks though!
    – Arla
    Nov 5, 2014 at 9:34

1 Answer 1

0

Adding the following line to the beginning of the script fixed it:

PATH=/usr/local/bin:$PATH

I assume Drush uses the $PATH in turn to call other commands.

3
  • Interesting, I don't see why that could cause a drush command not to be found. Fail possibly if it relies on other commands, but fail?
    – Letharion
    Nov 5, 2014 at 9:38
  • Possibly relevant: this is on Mac OS X.
    – Arla
    Nov 5, 2014 at 10:26
  • Yeah, "PHP OS: Darwin" gave that away, but I still don't see how that would cause this.
    – Letharion
    Nov 5, 2014 at 10:29

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.