Hey all,
I wish to execute a shell script on click of a button from a simple html page. How do I do this?
Need help!!!


Thanx,
Shreerang Patwardhan.

Recommended Answers

All 7 Replies

I've done something similar, but it was on a closed kiosk box. Unless you're doing something similar, I would advise against it, as security has to be very lax to do so.

You will either need to:

1) make the shell script executable by apache (or whatever web server you're running) or by anyone and, depending on the web scripting language you're using, run an exec command after a form submission. This will work if your shell script doesn't need other higher permissions, such as accessing hardware.

2) run a setuid script, so your shell script can be run by the web server as root or some other user with proper permissions.

You'll also need to make sure that executables are allowed where the shell script resides. Again, there's no secure way of doing this if it's on a networked machine.

Hey jmo,
My script is going to run on my machine itself; its a stand-alone thing. Can you please post a short example or exact steps to do what you have suggested. Like, how do I make my shell script executable from apache or where should the exec command be used?...
Please provide the detailed steps so that I would understand better!..
Thanx,
Shreerang Patwardhan.

Hey cfajohnson,
I checked out the link you have provided!...That exactly what I wish to do- The buton thing. But then do you suggest that I save my .sh file as .cgi???...

Thanx,
Shreerang Patwardhan.

Hey cfajohnson,
I checked out the link you have provided!...That exactly what I wish to do- The buton thing. But then do you suggest that I save my .sh file as .cgi???...


Web servers are usually set up to require CGI scripts to have a .cgi suffix, but they can be configured for whatever you like (using .htaccess -- google for it).

My wordfinder and anagram solver (http://cfaj.freeshell.org/wordfinder/) is entirely shell scripts, using index.cgi as the file name.

Hey cfajohnson,
You are not getting my problem! I am not an expert with shell scripting! What I want is- I want some steps which I can follow to achieve my target. I want to know what changes I will have to make in my shell script if any required! or what should my html code be to make the shell script run!
My shell script is currently executable! I execute it using the standard method ./filename.sh. I have created a simple HTML page which has a submit button only. Now, what I want is- When I click the button, the shell script should execute on my machine!
Can you please tell me the steps that I can follow to achieve the above mentioned objective?

Regards,
Shreerang Patwardhan.

Hey cfajohnson,
You are not getting my problem! I am not an expert with shell scripting! What I want is- I want some steps which I can follow to achieve my target. I want to know what changes I will have to make in my shell script if any required! or what should my html code be to make the shell script run!
My shell script is currently executable! I execute it using the standard method ./filename.sh. I have created a simple HTML page which has a submit button only. Now, what I want is- When I click the button, the shell script should execute on my machine!
Can you please tell me the steps that I can follow to achieve the above mentioned objective?


Read the source code of the first URL I posted. It's all there.

The script itself appears on that page.

You can see the actual page itself rather than the HTML the server sends out at http://cfaj.freeshell.org/testing/index.txt.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.