piped program in sendmail's /etc/aliases

8,599

Solution 1

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.

Solution 2

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:
8,599

Related videos on Youtube

icasimpan
Author by

icasimpan

Updated on September 17, 2022

Comments

  • icasimpan
    icasimpan over 1 year

    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:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    open ("RCV_MAIL", ">>/home/icasimpan/mail_received.txt") or die $!;
    while(<STDIN>){
       print RCV_MAIL;
    }
    close(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 [email protected], 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.

    • Admin
      Admin over 13 years
      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
    • Admin
      Admin over 13 years
      Temporarily made /home/icasimpan 777 just to rule out permission problems but still the error is the same.
  • icasimpan
    icasimpan over 13 years
    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
    icasimpan over 13 years
    Hmmm. Could that be a typo error? I don't see a < in this perl reference perlfect.com/articles/perlfile.shtml
  • Mikel
    Mikel over 13 years
    Sorry, my last comment was wrong. Please ignore it.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 13 years
    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).
  • icasimpan
    icasimpan over 13 years
    This has been helpful to me too. Thank you :)