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

Hi, I have a script with me, whose output needs to be displayed in a HTML via CGI… I have myShell.sh’, which needs to be executed in ‘myCGI.cgi’..
############################################################ #myShell.sh ############################################################ #!Perl_Interpreter_Location print "This is the list of files in ur current dir\n"; `ls -al`; print "End Of Script\n";
############################################################ #myCGI.cgi ############################################################ #!Perl_Interpreter Location Line 1 : print ”Content-Type : html/text ”; Line 2 : print “<HTML>”; Line 3 : print “<BODY>”; Line 4 : print ` etc/webtop/cgi-bin/myShell.sh ` Line 5 : print “</BODY>”; Line 6 : print “</HTML>”;
Now, this would execute the script, but unfortunately all the new-lines get replaced by a blank space..I tried executing with $().. But, it throws Compilation errors..

Replace Line 4(of myCGI.cgi) with the line below..
$("etc/webtop/cgi-bin/myShell.sh");
This gives me an error,
String found where operator expected at
/opt/ibm/netcool/webtop/profiles/TIPProfile/etc/webtop/cgi-bin/myCGI.cgi line 8, near "$("etc/webtop/cgi-bin/myShell.sh "" (Missing operator before "etc/webtop/cgi-bin/ myShell.sh "?) syntax error at /opt/ibm/netcool/webtop/profiles/TIPProfile/etc/webtop/cgi-bin/myCGI.cgi line 8, near "$("etc/webtop/cgi-bin/myShell.sh "" Execution of /opt/ibm/netcool/webtop/profiles/TIPProfile/etc/webtop/cgi-bin/myCGI.cgi aborted due to compilation errors.

Somebody,Anybody please help me out..

Replies are listed 'Best First'.
Re: Missing new-lines, when script executed in a CGI
by JavaFan (Canon) on May 11, 2010 at 14:03 UTC
    Is myShell.sh a shell or a perl program? If the latter, why isn't the she-bang line the first line? If the former, why the print (instead of echo), or the ls in backquotes?

    As for your main program, there should be two new lines after the content-type line, there should not be a space in front of the colon, nor should there be a space after the content type. Furthermore, line 4 seems to be missing a leading / in the path. And print `command` is a bit silly - it's saying "execute command, slurp in its output, then print it". Why not just execute the command? Whatever it outputs will be on your output. Oh, and Line 4 is missing a trailing semi-colon. And I do hope the "Line N :" thingies aren't there in reality - labels cannot contain spaces.

      Thanks for the quick reply JavaFan.. Its a Perl script,by '#!Perl_Interpreter_Location', i meant '#!/usr/bin/perl', isnt this SHE-BANG?
      sorry for the error-prone code..
      I had corrected all the issues pointed out by u, but still i end with the same problem.. Could you please tell me what else could be wrong!!
        Its a Perl script,by '#!Perl_Interpreter_Location', i meant '#!/usr/bin/perl', isnt this SHE-BANG?
        Yes. By my count, it's on the fourth line. '#!' is only recognized by the kernel if they are the first two bytes of the file.
Re: Missing new-lines, when script executed in a CGI
by Anonymous Monk on May 11, 2010 at 14:32 UTC
    but unfortunately all the new-lines get replaced by a blank space..

    They call that html

      :) thankx for the reply, it was quite helpful :P