2

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 test@gmail.com  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.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Stasv
  • 115
  • 1
  • 10

1 Answers1

3

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
AnFi
  • 10,493
  • 3
  • 23
  • 47
  • Thanks a lot! I don't think you've changed the original script, by the stdin tip was very useful, and it works now. do you mind editing the script in your answer? btw maybe you have an idea, if I would to pipe the e-mail into a c++ executable... should I immediately cin > in the code or is it transferred as an argument maybe ? – Stasv Jul 18 '13 at 10:43
  • @Stasv AFAIK Your `c++` program will get open STDIN. Just do not close it before reading what you want. – AnFi Jul 18 '13 at 12:45