Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

This script will simply create a file /tmp/testfile when you click on the button that says "Open Script".

http://stackoverflow.com/questions/6235785/run-a-shell-script-with-an-html-button

This requires 3 files.

1. The actual HTML Website with a button.
2. A php script which executes the script
3. A Script

The File Tree:

 

root@test:/var/www/html# tree testscript/
testscript/
??? index.html
??? testexec.php
??? test.sh

1. The main WebPage:

root@test:/var/www/html# cat testscript/index.html
<form action="/testscript/testexec.php">
    <input type="submit" value="Open Script">
</form>

 

2. The PHP Page that runs the script and redirects back to the main page:

root@test:/var/www/html# cat testscript/testexec.php
 
<?php
shell_exec("/var/www/html/testscript/test.sh");
header('Location: http://192.168.1.222/testscript/index.html?success=true');
?>

3. The Script :

root@test:/var/www/html# cat testscript/test.sh

#!/bin/bash

touch /tmp/testfile 


 
  • No labels