2

OK first of all, I am a PHP programmer but I have never done anything with CGI and don't know what it is. I know it stands for Common Gateway Interface, but I do not know what it does or what its for.

I was just told that I can upload a shell script to my cgi-bin folder and execute it.

I made a shell script myscript.sh and uploaded it to my cgi-bin folder. The first thing I noticed was my cgi-bin folder is a sibling to my root directory not a child. So I do not know how I would access it?

So I created a directory under my root called cgi-bin2 and put my script there (and chmod them to 755). Then I accessed it from my browser, and all it did was download the file.

Am I missing something?

Jim
  • 18,673
  • 5
  • 49
  • 65
JD Isaacks
  • 56,088
  • 93
  • 276
  • 422

1 Answers1

4

CGI should send a Content-Type header:

#!/bin/sh
printf "Content-Type: text/plain\n\n"
your_commands_here

Save as anything.sh (extension does not matter) in your cgi-bin folder and chmod 755. cgi-bin does not have to be a child of your public html folder, it can be an alias.

Lekensteyn
  • 64,486
  • 22
  • 159
  • 192
  • OK so I asked my host to add an alias, they did. I went to `mydomain.com/cgi-bin/myscript.sh` it loads, but just as a blank page. I don't see what I expect. I figured I would at least see the contents of myscript.sh but its blank, even when I view source. A little confused. – JD Isaacks Sep 03 '10 at 15:51
  • 1
    If you get a blank page with an Internal Server Error response, an error occured. Look in your error logs. – Lekensteyn Sep 03 '10 at 16:16