Joel Lee | 7 Aug 01:49 2010
Picon

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 <at> :/home/webs/site.com/scripts/echo.php"
From fodii2160 <at> 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 <at> 1356229:/var/mail/root"
From mudepeli7695 <at> 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?
____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail <at> lists.RWTH-Aachen.de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail
John Simpson | 7 Aug 03:29 2010

Re: procmail: Piping to a PHP script.

You need to comment out lines 2 and 4 of echo.php

On 8/6/10, Joel Lee <joel.lee8 <at> gmail.com> wrote:
> 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 <at> :/home/webs/site.com/scripts/echo.php"
> >From fodii2160 <at> 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 <at> 1356229:/var/mail/root"
> >From mudepeli7695 <at> 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?
>

--

-- 
John Wesley Simpson
SwaJime's Cove℠
www.swajime.com

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail <at> lists.RWTH-Aachen.de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail
Klaus Johannes Rusch | 7 Aug 10:15 2010
X-Face
Picon

Re: procmail: Piping to a PHP script.

John Simpson wrote:
> You need to comment out lines 2 and 4 of echo.php
>   
... and add the interpreter back in the .procmailrc file since the shell 
won't know how to handle a PHP file.

--

-- 
Klaus Johannes Rusch
KlausRusch <at> atmedia.net
http://www.atmedia.net/KlausRusch/
Joel Lee | 7 Aug 22:25 2010
Picon

Re: procmail: Piping to a PHP script.

Thanks for the suggestions.  Unfortunately, this doesn't help.  When commenting those lines out, it won't even run from the command line, with the interpreter specified in the file or with the interpreter specified in the command line.  It seems that php expects to find those lines.  When it doesn't, it just echos back the entire contents of the file as source code.

Thanks again.

On Fri, Aug 6, 2010 at 8:29 PM, John Simpson <john <at> swajime.com> wrote:
You need to comment out lines 2 and 4 of echo.php

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail <at> lists.RWTH-Aachen.de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail
Patrick Shanahan | 7 Aug 22:55 2010
Picon

Re: procmail: Piping to a PHP script.

* Joel Lee <joel.lee8 <at> gmail.com> [08-07-10 16:27]:
> Thanks for the suggestions.  Unfortunately, this doesn't help.  When
> commenting those lines out, it won't even run from the command line, with
> the interpreter specified in the file or with the interpreter specified in
> the command line.  It seems that php expects to find those lines.  When it
> doesn't, it just echos back the entire contents of the file as source code.

Undoubtedly the intent was *not* to run from the cl, but from the
procmail recipe which you requested, making your responce unthoughtful
and entirely inappropriate.  Did you attempt the script from your
procmail recipe?  You didn't say.

--

-- 
Patrick Shanahan         Plainfield, Indiana, USA        HOG # US1244711
http://wahoo.no-ip.org     Photo Album:  http://wahoo.no-ip.org/gallery2
Registered Linux User #207535                     <at>  http://counter.li.org
Michelle Konzack | 7 Aug 23:01 2010
Picon

Re: procmail: Piping to a PHP script.

Hello Joel Lee,

Am 2010-08-07 15:25:34, hacktest Du folgendes herunter:
> Thanks for the suggestions.  Unfortunately, this doesn't help.  When
> commenting those lines out, it won't even run from the command line, with
> the interpreter specified in the file or with the interpreter specified in
> the command line.  It seems that php expects to find those lines.  When it
> doesn't, it just echos back the entire contents of the file as source code.

Are you sure, you are using "php-cli" and not "php"?

"php-cli" (= php Command Line Interface) does  not  need  the  <?php ?>,
while "php" (the one used with webservers) does.

Thanks, Greetings and nice Day/Evening
    Michelle Konzack

-- 
##################### Debian GNU/Linux Consultant ######################
   Development of Intranet and Embedded Systems with Debian GNU/Linux

itsystems <at> tdnet France EURL       itsystems <at> tdnet UG (limited liability)
Owner Michelle Konzack            Owner Michelle Konzack

Apt. 917 (homeoffice)
50, rue de Soultz                 Kinzigstraße 17
67100 Strasbourg/France           77694 Kehl/Germany
Tel: +33-6-61925193 mobil         Tel: +49-177-9351947 mobil
Tel: +33-9-52705884 fix

<http://www.itsystems.tamay-dogan.net/>  <http://www.flexray4linux.org/>
<http://www.debian.tamay-dogan.net/>         <http://www.can4linux.org/>

Jabber linux4michelle <at> jabber.ccc.de
ICQ    #328449886

Linux-User #280138 with the Linux Counter, http://counter.li.org/
Joel Lee | 7 Aug 23:24 2010
Picon

Re: procmail: Piping to a PHP script.

Patrick:

When running it from the recipe, I find the following in my log:

procmail: Error while writing to "/usr/local/bin/php /home/webs/site/scripts/echo.php"

I also tried writing a simple bash script (echo.sh) and got a similar error message:

procmail: Error while writing to "/home/webs/site/scripts/echo.sh"

Very strange!

Michelle:

I'm sure it's php-cli.  I compiled php for apache as a module, so the only thing I could be running from the command line is php-cli.

[root <at> norfair scripts]# /usr/local/bin/php --version
PHP 5.3.3 (cli) (built: Aug  5 2010 12:55:47)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

[root <at> norfair scripts]# /usr/local/bin/php /home/webs/site/scripts/echo.php
echo "hi.";

Thanks again.

On Sat, Aug 7, 2010 at 3:55 PM, Patrick Shanahan <ptilopteri <at> gmail.com> wrote:
* Joel Lee <joel.lee8 <at> gmail.com> [08-07-10 16:27]:
> Thanks for the suggestions.  Unfortunately, this doesn't help.  When
> commenting those lines out, it won't even run from the command line, with
> the interpreter specified in the file or with the interpreter specified in
> the command line.  It seems that php expects to find those lines.  When it
> doesn't, it just echos back the entire contents of the file as source code.

Undoubtedly the intent was *not* to run from the cl, but from the
procmail recipe which you requested, making your responce unthoughtful
and entirely inappropriate.  Did you attempt the script from your
procmail recipe?  You didn't say.

--
Patrick Shanahan         Plainfield, Indiana, USA        HOG # US1244711
http://wahoo.no-ip.org     Photo Album:  http://wahoo.no-ip.org/gallery2
Registered Linux User #207535                     <at> http://counter.li.org
____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail <at> lists.RWTH-Aachen.de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail <at> lists.RWTH-Aachen.de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail
John Simpson | 8 Aug 01:03 2010

Re: procmail: Piping to a PHP script.

On Sat, Aug 7, 2010 at 3:25 PM, Joel Lee <joel.lee8 <at> gmail.com> wrote:
> Thanks for the suggestions.  Unfortunately, this doesn't help.  When
> commenting those lines out, it won't even run from the command line, with
> the interpreter specified in the file or with the interpreter specified in
> the command line.  It seems that php expects to find those lines.  When it
> doesn't, it just echos back the entire contents of the file as source code.
>
> Thanks again.
>
> On Fri, Aug 6, 2010 at 8:29 PM, John Simpson <john <at> swajime.com> wrote:
>>
>> You need to comment out lines 2 and 4 of echo.php
>>
>
> ____________________________________________________________
> procmail mailing list   Procmail homepage: http://www.procmail.org/
> procmail <at> lists.RWTH-Aachen.de
> http://mailman.rwth-aachen.de/mailman/listinfo/procmail
>
>

I tested this before I posted it to the list:

john <at> system76-pc:~$ aptitude show php5-cli
Package: php5-cli
State: installed
 ...

john <at> system76-pc:~$ dpkg -L php5-cli
/.
/etc
/etc/php5
/etc/php5/cli
/usr
/usr/bin
/usr/bin/php5
/usr/share
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/php5.1.gz
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/php5-cli
/usr/share/doc
/usr/lib
/usr/lib/php5
/usr/lib/php5/20090626
/etc/php5/cli/conf.d
/usr/share/doc/php5-cli

john <at> system76-pc:~$ cat echo.php
#!/usr/bin/php
#<?php
echo "hi.";
#?>
john <at> system76-pc:~$ echo 'goodbye' | ./echo.php

#hi.john <at> system76-pc:~$ ls -la /usr/bin/php
lrwxrwxrwx 1 root root 21 2010-08-06 20:23 /usr/bin/php -> /etc/alternatives/php
john <at> system76-pc:~$ ls -la /etc/alternatives/php
lrwxrwxrwx 1 root root 13 2010-08-06 20:23 /etc/alternatives/php ->
/usr/bin/php5
john <at> system76-pc:~$

Two questions...
1) Is echo.php still set as executable?
2) Did you specify the full path to echo.php in your procmail script?

--

-- 
John Wesley Simpson
SwaJime's Cove℠
www.swajime.com

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail <at> lists.RWTH-Aachen.de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail
Joel Lee | 8 Aug 02:28 2010
Picon

Re: procmail: Piping to a PHP script.

John-

1: Yes, I've set permissions to 777 on echo.php.

2: Absolutely.

On Sat, Aug 7, 2010 at 6:03 PM, John Simpson <john <at> swajime.com> wrote:
On Sat, Aug 7, 2010 at 3:25 PM, Joel Lee <joel.lee8 <at> gmail.com> wrote:
> Thanks for the suggestions.  Unfortunately, this doesn't help.  When
> commenting those lines out, it won't even run from the command line, with
> the interpreter specified in the file or with the interpreter specified in
> the command line.  It seems that php expects to find those lines.  When it
> doesn't, it just echos back the entire contents of the file as source code.
>
> Thanks again.
>
> On Fri, Aug 6, 2010 at 8:29 PM, John Simpson <john <at> swajime.com> wrote:
>>
>> You need to comment out lines 2 and 4 of echo.php
>>
>
> ____________________________________________________________
> procmail mailing list   Procmail homepage: http://www.procmail.org/
> procmail <at> lists.RWTH-Aachen.de
> http://mailman.rwth-aachen.de/mailman/listinfo/procmail
>
>

I tested this before I posted it to the list:

john <at> system76-pc:~$ aptitude show php5-cli
Package: php5-cli
State: installed
 ...

john <at> system76-pc:~$ dpkg -L php5-cli
/.
/etc
/etc/php5
/etc/php5/cli
/usr
/usr/bin
/usr/bin/php5
/usr/share
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/php5.1.gz
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/php5-cli
/usr/share/doc
/usr/lib
/usr/lib/php5
/usr/lib/php5/20090626
/etc/php5/cli/conf.d
/usr/share/doc/php5-cli

john <at> system76-pc:~$ cat echo.php
#!/usr/bin/php
#<?php
echo "hi.";
#?>
john <at> system76-pc:~$ echo 'goodbye' | ./echo.php

#hi.john <at> system76-pc:~$ ls -la /usr/bin/php
lrwxrwxrwx 1 root root 21 2010-08-06 20:23 /usr/bin/php -> /etc/alternatives/php
john <at> system76-pc:~$ ls -la /etc/alternatives/php
lrwxrwxrwx 1 root root 13 2010-08-06 20:23 /etc/alternatives/php ->
/usr/bin/php5
john <at> system76-pc:~$

Two questions...
1) Is echo.php still set as executable?
2) Did you specify the full path to echo.php in your procmail script?

--
John Wesley Simpson
SwaJime's Cove℠
www.swajime.com

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail <at> lists.RWTH-Aachen.de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail
Joel Lee | 8 Aug 03:27 2010
Picon

Re: procmail: Piping to a PHP script.

Okay, guys . . .

I was able to resolve my issue by using a sendmail .forward file to pipe mail to the script instead of procmail.  What I was actually trying to do was pipe my mail to a PHP script which would then route the mail to a MySQL database.  That script was not working (it was generating the same errors as my echo.php file).  However, now that I'm routing via a .forward instead of a .procmailrc, all is good (mail is being received and routed by the PHP script).

For my own edification, I'd still like to know what the heck went wrong with procmail.  I've used it for years and have never had any trouble with it.  In fact, it always seemed to "just work", if you know what I mean.  It generally didn't matter how I configured it, as long as I checked the basics (made sure the script executed from the command line, checked permissions, etc.) it always worked great.  I've never tried so many different configurations and had them all fail!  In fact, I have another machine running the same OS (CentOS 5) with the same versions of procmail and sendmail.  I have the same scripts running on that machine and procmail routes to the scripts just fine.  The only difference I can think of is that on the problem machine, I'm running a 64-bit version of CentOS and have compiled all of my programs as 64-bit executables.  That seems like a long shot, though.

At any rate, if anyone else is curious, I'm willing to cooperate.  Otherwise, I've found my solution.  Thanks to everyone who patiently offered to help!

Regards,

Joel


____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail <at> lists.RWTH-Aachen.de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail

Gmane