Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
hi well i have redhat9.0 and im kinda new to this os need help on what to open to write a perl script on linux and where to save it. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Oct 2005
    Posts
    110

    cgi-bin~perl


    hi well i have redhat9.0 and im kinda new to this os need help on what to open to write a perl script on linux and where to save it. and do i really need perl to use perl to use cgi-bin. this is way over my head.

  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    Um...

    To write a Perl script, you can use any text editor. I personally write Perl from the commandline, using the vi text editor, but if you use a GUI, gedit (Gnome) or kate (KDE) will both work.

    Make sure to make the first line of the file "#!/usr/bin/perl", so that you can simply invoke the file instead of needing to name a parser (important for CGI work).

    Also, to write CGI, you need to be sure that you use the CGI module.


    As far as where to save it, this depends on a few things. If you're simply testing a script, well, CGI simply writes out HTML, so you can save and run the script from anywhere.

    If you're setting it up on a webserver, you need to save it to wherever the server knows to EXECUTE scripts, as opposed to displaying them. Such a directory is often called cgi-bin.


    Hope this helps!

  3. #3
    Linux Newbie
    Join Date
    Oct 2005
    Posts
    110

    cgi-bin~perl

    ok well i want to add the script to my server, i do know where the cgi-bin folder is at but when i wrote the script it just like a plain notepad. i can even open it and edit the script. i save it as hello.pl is that right. well here is the script that i wrote

    #!c:\perl\bin

    print "content-type: text/html\n\n\";
    print "<html>";
    print "<head>";
    print "<title>first perl test</title>";
    print "</head>";
    print "<body>";
    print "your ip address is: $env{remote_host}";
    print "</body>";
    print "</html>";

    correct me if you see an error
    this one i save it as 10-01.pl
    so i type http://localhost/cgi-bin/10-01.pl
    and i get an error
    that the server can't open perl scripts

  4. #4
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    Have you associated the ".pl" extension with execution? You might want to change the extension to ".cgi".

  5. #5
    Linux Enthusiast
    Join Date
    Aug 2005
    Location
    Hell
    Posts
    514
    Instead of "c:\perl\bin", you need the actual path to Perl on your computer, which you can find with "which perl"; it's usually "/usr/bin/perl".

    Also, you have to make sure that the script is executable: "chmod +x hello.pl"

    If that doesn't work, post your /etc/httpd/conf/httpd.conf here.

  6. #6
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    Because his line is a Windows path, I'm gonna assume he's on a Windows machine, which means shebang lines don't work.

    Also, since he's using localhost, I assume the server is Windows, so again, shebang lines won't work.

  7. #7
    Linux Newbie
    Join Date
    Oct 2005
    Posts
    110

    cgi-bin

    just to let you guys know im using redhat 9.0 server
    i change: "c:\perl\bin" to "usr/bin/perl
    so at this point at this this code: #!/usr/bin/perl
    print "hello" save as hello.pl and it work i save made another one and save it as 10-01.cgi and it work too
    both .pl and .cgi work but the i do this code:
    #!/usr/bin/perl

    print "content-type: text/html\n\n\";
    print "<html>";
    print "<head>";
    print "<title>first perl test</title>";
    print "</head>";
    print "<body>";
    print "your ip address is: $env{remote_host}";
    print "</body>";
    print "</html>";

    im try to display my ip address in my browser
    i save this at home/username: fail
    i save this at cgi-bin dir: fail can you take a look the code is correct and address me about it, and also what things do i need to look at since i know .cgi and .pl work fine with other codes. i test: 127.0.0.1 and pc reply back with:
    64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.034 ms and so on

  8. #8
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    Quote Originally Posted by flacko21
    im try to display my ip address in my browser
    i save this at home/username: fail
    i save this at cgi-bin dir: fail can you take a look the code is correct and address me about it, and also what things do i need to look at since i know .cgi and .pl work fine with other codes. i test: 127.0.0.1 and pc reply back with:
    64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.034 ms and so on
    You say 'fail'. Can you be more specific? Are you getting a 500 error (that is, the script has a problem), or is it returning the incorrect address?

  9. #9
    Linux Newbie
    Join Date
    Oct 2005
    Posts
    110

    cgi-bin~perl

    at this point i set the path:
    cd /var/www/cgi-bin
    then once im in path i type perl myip.cgi and i get back i reply back like this:
    content-type: text/html

    <html><head><title>my ip address</title></head><body>your ip address is: </body></html>
    so i open my browser and type 127.0.0.1/scripts/myip.cgi
    and this is what i get back http://channels.netscape.com/search/default.jsp

    i type in scripts cause that what they told me to type. can you see what im doing wrong

  10. #10
    Linux Newbie
    Join Date
    Oct 2005
    Posts
    110

    cgi-bin~perl

    Server error!

    The server encountered an internal error and was unable to complete your request.

    Error message:
    Premature end of script headers: 12.cgi

    If you think this is a server error, please contact the webmaster

    Error 500

    127.0.0.1
    Sun 01 Jan 2006 01:03:33 PM CST
    Apache/2.0.40 (Red Hat Linux)
    this is same code i did but name it 12.cgi

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •