execute shell script using CGI for html site

hi there
im currently in the process of creating a website for use basically within our org. im using a os x machine and installed MAMP - which includes Apache, mysql... the site will be used by techs to primarily install pkgs files onto os x devices. i would like to have buttons or hyperlinks (doesnt matter) that when the tech selects the object (e.g. a pkg file - adobe reader)... a sh script is executed that will basically install the app onto the os x device. i have placed a test shell script in the cgi-bin folder and changed ownership so its executable (chmod +x scriptname).
the test script looks like this:
#!/bin/sh
echo "content-type: text/html"
""
mkdir /users/test/thisisatestfolder

in the html page - i dont know how i would "call it" , e.g. form etc...
i dont even know if the script is set-up right as well
any help would be great
thanks!

The base shell and web service are not too compatible, both because shell needs help decoding URLencoded strings and because it is easy to open security holes (shell injection, I guess you could call it) with metacharacters in input. You can do some simple things, especially when the user input is not required, like a report with no inputs and no forms, just information or links.

The rules of CGI are pretty simple, and executables in you cgi-bin subtree will get called by the web server. Scripts may not act like they do interactively, since there is no tty. Basicly, you write to stdout a good http header minus the first line, blank line and whatever document you want, then exit 0. Get input is by env var., and post by read-it-yourself from stdin. There are a handful of support variables. You can see them with this cgi script:

#!/usr/bin/ksh
 
echo "Content-type:text/plain
 
CGI Environment:
'
 
set 
 
echo '
---- END ----'
 

This could be dangerous, but generally it will depend on what scripting language you are using, for example with PHP behind the scenes you could use system(); / exec(); calls, with Perl/CGI you could use the same commands, as long as you put your script in executable directory, as in:

#!/bin/bash
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Bash as CGI"
echo "</title></head><body>"

echo "<h1>Hello world</h1>"
echo "Today is $(date)"

echo "</body></html>"

and all this is enclosed in a script that has executable rights, most of the times placed in folder like "cgi-bin".