perl_devel has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,
I have met with a complex problem, I am just
developing some applications and my requirement is when
i shoot a mail to a mailing list and that should trigger a perl script.

In the perl script i use some system command to get the data of the sender `de aliases@xx.com` which will will give some data mapped to this aliases.

When i test this using command line perl parser.pl or thru browser http://xxx.com/cgi-bin/parser.pl this works and gives the expected output of de . but when i trigger this using a mail it says "File or directory not found". I tried even system command it doesnt work if i trigger this using a mailing list but the other way (commandline or thru CGI it works)


Why is this any clues and solutions ?


Thanks and Regards
P.B.Sathish Kumar

Replies are listed 'Best First'.
Re: Executing system command
by puploki (Hermit) on Jul 28, 2005 at 05:14 UTC
    I don't fully understand the intricacies here, but I assume you're using Exim or Postfix which allows you to pipe an email address/alias to a command.

    It's stabbing in the dark a little, but you may want to check permissions - often Exim will try and execute such an external script as the user Exim is running as (which should be a non-privileged user) so it may not have read/write access to the files you're expecting it to have

    Also, it's possible that the MTA is expecting some sort of feedback from the script after it hands the mail over

    Sorry I can't offer anything more concrete, but perhaps if you could post some more details about your Perl and its plugin to your MTA that might help.

    --Alex

Re: Executing system command
by sk (Curate) on Jul 28, 2005 at 04:29 UTC
    I am not sure how you are trigerring this using your mailing list but you may want to try using the full path for  de. Also you can add debug statements in your program so that you can figure exactly at what point this program fails

    -SK

      There is a way to trigger perl script thru mailing list
      Aliases file will direct which perl script to trigger
      (eg) i want to trigger  parse.pl on mailing trigger@xx.com
      
      aliases mapped for trigger will be
      
      trigger | parse.pl
      
        I am not familiar with mailing lists so I cannot help you much there... Since you are saying the problem does not occur when you run the script from the command line it makes me wonder the script failing because it cannot excecute your command

        . Here is a code snippet

        #!/usr/bin/perl -w print `date`; print `dfs`; print `date1`;

        In the above code, the first line will execute, the second line is referencing my ".alias file" (i guess this is nothing to do with your mailing list alias your are talking about), the third line is an invalid command.

        I get the following error as Perl cannot find the commands

        Thu Jul 28 00:01:32 CDT 2005 Can't exec "dfs": No such file or directory at sys line 4. Can't exec "date1": No such file or directory at sys line 5.

        Is this what you are referring to File or Directory Not Found? Is that the exact error? I am confused because I cannot figure out "what" is "not found" - perl script? or one of the commands inside the perl script? That's why i asked you to put full path for the de command. It could also be that your Perl script cannot be located by your mailing list trigger in which case give it a full path on that alias file

        . It will be helpful if you could add some debug statements in your script and say "reached line #: __LINE__" etc. By that you know where it is failing and probably post your code around that if it is too big to post

        If the problem is in "executing" the perl script itself then it is probably not perl related and you might want to check our your mailing list app usenet

        -SK