Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying some sort of auto-subscription via a homegrown script. I know it can be achieved by mailing lists such as Mailman but I also want to learn at the same time on how to do it by hand.

Here's the simple script:


use strict;
use warnings;

open ("RCV_MAIL", ">>/home/icasimpan/mail_received.txt") or die $!;
   print RCV_MAIL;

I attached the above script in /etc/aliases using the syntax:

subscribe: | /home/icasimpan/parse-subscribe.pl

and run

$ sudo newaliases

It's still a very bare script. Just testing out if I my syntax in /etc/aliases is correct.

But when I tried emailing subscribe@mydomaintests.tld, it returns something like:

Delivery failure 69

I'm using Lotus Notes so my google search directed me to this link. Apparently, something to do with the file...Not sure.

The command is executable, in fact I tried making it 777 and even created the mail_received.txt in the directory just to ensure I have no file permission problem but still the same.

Can anyone pitch in please?

Thanks in advance.

share|improve this question
Side note: I also tried my script from command line and it works....$ echo "CLI Test"|./parse-subscribe.pl and I could get the "CLI Test" inside mail_received.txt – icasimpan Jan 28 '11 at 3:16
Temporarily made /home/icasimpan 777 just to rule out permission problems but still the error is the same. – icasimpan Jan 28 '11 at 3:23
up vote 4 down vote accepted

If you're running a sendmail with smrsh set up (common in a lot of default configurations) you will need to run the piped command out of /etc/smrsh/. It can either be a symlink or a copy of the script, but if sendmail has 'smrsh' defined, it will need to be run from that directory. For example:

subscribe: | /etc/smrsh/parse-subscribe.pl

Check the sendmail documentation on smrsh for more details.

share|improve this answer
Haha, this works. Thank you so much! :) – icasimpan Jan 31 '11 at 0:36

You need to quote the "alias" if it has a space in it:

subscribe: "| /home/icasimpan/parse-subscribe.pl"

or remove the space:

subscribe: |/home/icasimpan/parse-subscribe.pl
share|improve this answer
This has been helpful to me too. Thank you :) – icasimpan Jan 31 '11 at 0:37
open ("RCV_MAIL", ">>/home/icasimpan/mail_received.txt") or die $!;
   print RCV_MAIL;

is wrong.

If you're trying to print lines from STDIN to mail_received.txt, you would need:

open (RCV_MAIL, ">>/home/icasimpan/mail_received.txt") or die $!;
while (<STDIN>) {
   print RCV_MAIL $_;

because print with one argument takes the argument to mean the list to print, not the filehandle to print it to.

$ perldoc -f print
print LIST

Also, no need for quotes around the filehandle name in open. Just use RCV_MAIL.

share|improve this answer
Thanks for the suggestion Mikel but it doesn't seem to work. I tried print $_ RCV_MAIL; or print RCV_MAIL $_; but no luck... – icasimpan Jan 28 '11 at 8:19
Hmmm. Could that be a typo error? I don't see a < in this perl reference perlfect.com/articles/perlfile.shtml – icasimpan Jan 28 '11 at 8:32
Sorry, my last comment was wrong. Please ignore it. – Mikel Jan 28 '11 at 8:32
open("RCV_MAIL", …) is horrible style, but it does work (Perl converts the string to a symbol). print RCV_MAIL works as well (it's a FILEHANDLE followed by an empty LIST, this only works if FILEHANDLE is a bare word IIRC). – Gilles Jan 28 '11 at 20:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.