procmail is not executing scripts correctly
I'm having a strange issue with running scripts (perl and ruby failing) from incoming mail locally delivered by procmail.
The system is CentOS 5.5 with postfix as my mailer, then a .forward set up to send email on to procmail. The .procmailrc and scripts are identical to a working setup on an Ubuntu server.
Here's the .procmailrc:
PATH= /usr/local/bin:/usr/bin:${PATH}
SHELL=/bin/bash
MAILDIR=$HOME/Maildir
DEFAULT=${MAILDIR}/
LOGABSTRACT=yes
LOGFILE=$HOME/Maildir/proclog
VERBOSE=YES
:0 wc
* ^To.*web@mydomain.com
| /home/web/perltest.pl
Here's 开发者_运维问答the perl script:
#!/usr/bin/env perl
system("touch /home/web/touchedfile");
And then the failure in the log upon receiving email:
procmail: Executing "/home/web/perltest.pl"
/home/web/perltest.pl: line 3: syntax error near unexpected token `"touch /home/web/touchedfile"'
/home/web/perltest.pl: line 3: `system("touch /home/web/touchedfile");'
The line endings are all UNIX. The script runs fine from the command line.
The whole setup works fine if I pipe to procmail directly from the command line, but when it's invoked as part of the local delivery process, the #! line seems to be ignored in the script.
I can get the perl script to run if I explicitly execute perl in the pipe, like so:
:0 wc
* ^To.*web@mydomain.com
| perl /home/web/perltest.pl
... but I really don't want to admit defeat and do that.
The problem is selinux, if you turn that off it should work. I'm not sure how to fix it with selinux enabled.
Here's a way to fix it and still have selinux running. Run chcon system_u:object_r:procmail_exec_t
on your perl or ruby scripts. I've verified that is a fix, but I'm not familiar enough with selinux to be sure it's the "correct" fix.
精彩评论