Find the answer to your Linux question:
Results 1 to 2 of 2
Hello. I have my .procmailrc file set up to pipe mail to a simple php script I've written. The only thing the script does at this point is echo back ...
  1. #1
    eon
    eon is offline
    Just Joined!
    Join Date
    Aug 2010
    Posts
    2

    procmail: Piping to a PHP script.

    Hello.

    I have my .procmailrc file set up to pipe mail to a simple php script I've written. The only thing the script does at this point is echo back a "hello" message. However, procmail does not execute the script properly.

    Here's my script (/home/webs/site.com/scripts/echo.php):

    Code:
    #!/usr/local/bin/php
    <?php
    echo "hi.";
    ?>
    When I execute this script from the shell, it performs as expected. A message is echoed to the terminal ("hi.") and the script quits.

    Here is my .procmailrc:

    Code:
    LOGFILE=/var/log/procmail.log
    VERBOSE=YES
    :0
    | /home/webs/site.com/scripts/echo.php
    And here is what is logged by procmail:


    Code:
    procmail: [11765] Fri Aug  6 16:12:48 2010
    procmail: Executing "/home/webs/site.com/scripts/echo.php"
    procmail: [11765] Fri Aug  6 16:12:48 2010
    procmail: Assigning "LASTFOLDER=/home/webs/site.com/scripts/echo.php"
    procmail: Notified comsat: "root@:/home/webs/site.com/scripts/echo.php"
    From fodii2160@quicknet.nl  Fri Aug  6 16:12:48 2010
     Subject: Heard of the fellowship?
      Folder: /home/webs/site.com/scripts/echo.php                     728
    /home/webs/site.com/scripts/echo.php: line 2: ?php: No such file or directory
    /home/webs/site.com/scripts/echo.php: line 4: syntax error near unexpected token `newline'
    /home/webs/site.com/scripts/echo.php: line 4: `?>'
    procmail: [11769] Fri Aug  6 16:13:00 2010
    procmail: Executing "/home/webs/site.com/scripts/echo.php"
    /home/webs/site.com/scripts/echo.php: line 2: ?php: No such file or directory
    /home/webs/site.com/scripts/echo.php: line 4: syntax error near unexpected token `newline'
    /home/webs/site.com/scripts/echo.php: line 4: `?>'
    procmail: [11769] Fri Aug  6 16:13:00 2010
    procmail: Error while writing to "/home/webs/site.com/scripts/echo.php"
    procmail: Assigning "LASTFOLDER=/home/webs/site.com/scripts/echo.php"
    procmail: Locking "/var/mail/root.lock"
    procmail: Assigning "LASTFOLDER=/var/mail/root"
    procmail: Opening "/var/mail/root"
    procmail: Acquiring kernel-lock
    procmail: Unlocking "/var/mail/root.lock"
    procmail: Notified comsat: "root@1356229:/var/mail/root"
    From mudepeli7695@rr.com  Fri Aug  6 16:13:00 2010
     Subject: Intense - the secret
      Folder: /var/mail/root
    It appears that when procmail runs the script, the "#!/usr/local/bin/php" isn't recognized, so it's being run as if it's a shell script instead of using the php interpreter. This would explain errors such as "line 2: ?php: No such file or directory". (If you just run a php script from the command line without the path to the interpreter, that's exactly the kind of error you'll get).

    I've tried modifying my .procmailrc file like so:

    :0
    | /usr/local/bin/php /home/webs/site.com/scripts/echo.php

    (I removed the path to the interpreter from the script itself when running as above.) No joy. I'm at my wit's end here.

    If the script were being executed properly, I would see the "hi." message being echoed back in procmail.log instead of the execution errors.

    Help?
    Last edited by eon; 08-06-2010 at 10:49 PM. Reason: Added procmail log as a text attachment.

  2. #2
    eon
    eon is offline
    Just Joined!
    Join Date
    Aug 2010
    Posts
    2
    For anyone who is curious, I fixed my problem by routing via a sendmail .forward file instead of through .procmail.

    I was actually working with a PHP script that routes mail to a MySQL database. That script wasn't working when I piped through procmail, but as soon as I used the .forward file instead, it worked great.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...