Kevin Duke Kevin Duke - 2 months ago 18
HTML Question

Run a shell script with an html button

I want to launch a bash script when a button is pressed on a website.
This is my first attempt:

<button type="button" onclick="/path/to/name.sh">Click Me!</button>


But no luck. Any suggestions?

nsg nsg
Answer

As stated by Luke you need to use a server side language, like php. This is a really simple php example:

<?php
if ($_GET['run']) {
  # This code will run if ?run=true is set.
  exec("/path/to/name.sh");
}
?>

<!-- This link will add ?run=true to your URL, myfilename.php?run=true -->
<a href="?run=true">Click Me!</a>

Save this as myfilename.php and place it on a machine with a web server with php installed. The same thing can be accomplished with asp, java, ruby, python, ...