pipe mail / get input from stdin
| From: | Dieter Kneffel | Date: | Wed, 15 Nov 2000 01:23:47 +0000 |
| Subject: | pipe mail / get input from stdin | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-25320@lists.php.net to get a copy of this message | ||
Can someone explain, why this is working when started
as a shell script manually on the shell (saves input from
stdin properly to a file) but not when pipeing (e.g. utilizing
/etc/aliases)an email into it (creates an empty file!)?
On the other hand, the second (unix shell) script below
works just fine when triggered by an email.
The line in /etc/aliases is something like:
xyz: "|/path/to/my/script"
[Of course, I have PHP as CGI..]
Thank you very much!!!
dk
------------------ PHP SHELL SCRIPT --------------
#!/usr/local/bin/php -q
<?
// tried all of these but without success!
// $fp = fopen("php://stdin", "r");
// $fp = fopen("/dev/fd/0", "r");
$fp = fopen("/dev/stdin","r");
while(($buf=fgets($fp, 512)) != false) {
$dump .= $buf;
}
fclose($fp);
$fpf = fopen("/tmp/mail.txt","w");
fputs($fpf,$dump);
fclose($fpf);
?>
The above should work like this one:
------------------ SHELL SCRIPT --------------
#!/bin/sh
LOGDIR="/tmp/mail.txt"
#
# Read stdin
#
while read LINE
do
echo $LINE >>$LOGDIR
done