Search code examples
emailprocmail

procmail not piping e-mail content to a file


I have a postfix server and procmail installed and working. The problem is when I try to output the content of an e-mail to a file.

I have the following script: /var/log/user1/fooscript.sh

#!/bin/bash
echo "Trying to get e-mail" > success.txt
echo $1 >> success.txt

/var/log/user1/.procmailrc

VERBOSE=off
PMDIR=$HOME/.procmail
LOGFILE=$PMDIR/procmail.log
INCLUDERC=$PMDIR/rc.filters

/var/log/user1/.procmail/rc.filters

:0
* ^From:(.*\<)?(test@gmail\.com)\>
| /var/log/user1/fooscript.sh

After sending an e-mail, /var/log/user1/.procmail/rc.filters contains:

From [email protected]  Thu Jul 18 05:08:13 2013
  Folder: /var/log/user1/fooscript.sh                       513

but the success file only shows:

Trying to get e-mail  
(empty line)

I've chmod 777 all files and directories, so don't think its a permissions issue.

Any help would be greatly appreciated.


Solution

  • Your script gets the message via standard input (STDIN). Try:

     #!/bin/bash
     echo "Trying to get e-mail" > success.txt
     # append data read from STDIN to success.txt file
     cat >> success.txt
    

    BTW for more complicated scripts use custom lock to avoid running two scripts in parallel:

    :0 w :fooscript.lock
    * ^From:(.*\<)?(test@gmail\.com)\>
    | /var/log/user1/fooscript.sh