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

Hello - I have the following CGI in CGI-BIN, its short sendmail program:
#!/usr/bin/perl strict my $sendmail = "/usr/sbin/sendmail -t"; my $from = "From: Foo@Bar.com\n"; my $subject = "Subject: Request to share information\n"; my $content = "Hello..."; my $to = "To: user\@ameritech.net\n\n"; my $recipient = "schafferm\@ameritech.net\n\n"; open(SENDMAIL, "|$sendmail $recipient") or die "Cannot open $sendmail: $!"; print SENDMAIL $subject; print SENDMAIL $from; print SENDMAIL $to; print SENDMAIL $content; close(SENDMAIL);

I then call this from HTML - via a java scripted button w/ /cgi-bin/sendanon.cgi

sendanon.cgi has been set wide open for the time being with chmod 777.

the script executes and yields the following error:

[Mon Jul 15 08:16:26 2002] [error] (2)No such file or directory: exec of /CompleteAct/domains/organexchange.org/http-lib/cgi +- bin/sendanon.cgi failed

any ideas?

edited: ~Tue Jul 16 21:45:35 2002
by footpad: Removed ^M characters from code and added fromatting tags

Replies are listed 'Best First'.
Re: Calling Perl from HTML
by Abigail-II (Bishop) on Jul 15, 2002 at 13:58 UTC
    Well, it's not a message generated by your program, as your only die() starts with "Cannot open". Which leaves the funky (and incorrect) she-bang line. I guess you want to start with:
    #!/usr/bin/perl -w use strict;
    (Note: no ^M).

    Abigail

Re: Calling Perl from HTML
by flocto (Pilgrim) on Jul 15, 2002 at 13:58 UTC

    I'd say your perl interpreter has problems opening the file "strict". Your first lines should look like this:

    #!/usr/bin/perl -wT # or whereever your perl executable resides.. use strict;

    Regards,
    -octo

      made that chance - same problem..
Re: Calling Perl from HTML
by Aristotle (Chancellor) on Jul 15, 2002 at 16:22 UTC
    It should look like this (incl some unrelated improvements) - note the lack of ^M:
    #!/usr/bin/perl -w use strict; my $sendmail = "/usr/sbin/sendmail -t"; my $recipient = "schafferm\@ameritech.net"; open(SENDMAIL, "|$sendmail $recipient") or die "Cannot pipe to $sendma +il: $!"; print SENDMAIL <<"END_MAIL"; From: Foo\@Bar.com Subject: Request to share information To: user\@ameritech.net Hello... END_MAIL close(SENDMAIL); print "Content-type: text/plain\n\nMail sent.";

    Don't forget something like the last line. The webserver expects the script to produce a valid HTTP reply.

    In reply to grag: no, just didn't think of it :-)

    Makeshifts last the longest.

        Nope - you are correct - probably s/b w/ ' instead of " - eventually I will be passing a $scalar.
Re: Calling Perl from HTML
by stajich (Chaplain) on Jul 15, 2002 at 14:00 UTC
    Wow, I definitely get stupid points for today. Ignore the alarmist idiot monk that was posing as myself this morning. Ignore the rest of my post and use strict, get rid of those ^M and test the script on the cmdline to see where you are failing exactly.

    Removed stupid alarmist speak about how to securify your CGI scripts

    ===

    This code is pretty insecure, I really suggest reading some more about writing secure cgi programs.

    Now as to your specific problem, the sendmail program may not be runnable by your http process, I would consider another module like Mail::Mailer or its kin.

      What is your point? The program as presented isn't insecure at all - everything is set from within the program. It would pass -T without a problem.

      Of course you get problems if you do what you suggested above. But then, you will get the same problem if you do

      system "/bin/rm -rf /";
      But that's just stupid, not insecure.

      Abigail

        Plot Thickens: Turns out that the CGI is running, in that it sends an email to the account I specify, yet it still shows the error as reported -- I placed a generic print "test"; before the Close (SENDMAIL) and that never happens?!
        You're right and I definitely failed the stupid test today, sorry to have wasted your time/space on that.