How can I execute a shell script from an html link?

I want to execute a shell script when clicking on an html link. I want the output of the script to be shown on the webpage. Whats the best way to achieve this?

Hi.

The simplest way is probably just to put the script into your cgi-bin directory.

You need something like this at the top of your script (after the shebang, but before echo�ng anything else), otherwise you'll get a 500 error.

#!/bin/bash
echo "Content-type: text/html"
echo

and then have a link to the script in your web page:
i.e.

<a href="/cgi-bin/myScript.sh">Run Script</a>

Not an expert but...

This sounds like a server-side issue
and you might want to consider either
perl, python or php.

A.

You don't need any of those things to execute a shell script from a Web Page.

So long as you send the right header information, you could write it in anything.

Besides, it wasn't an issue, only a question.

S.

Thanks for the information guys.

Hey guys, so I basically wrote a simple script that ssh's into different machines and grabs some info. However, the script isn't instantaneous with the output and it seems to give me a blank screen when I execute from a link.

My question is how can I make apache refresh the page, or wait till the script finishes, then display the output?

You can use :

<META HTTP-EQUIV="Refresh"CONTENT="10; URL=http://abcde.com">

It will refresh to URL every 10 seconds