Welcome to FreeSoftwareServers Confluence Wiki

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:

cat<<'EOF'>index.html
<form action="testexec.php">
    <input type="submit" value="Open Script">
</form>
EOF


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

cat<<'EOF'>testexec.php
<?php
shell_exec("test.sh");
header('Location: https://odev.freesoftwareservers.com/webhooks/index.html?success=true');
?>
EOF

3. The Script :

cat<<'EOF'>test.sh
#!/bin/bash

touch /tmp/testfile 
EOF



  • No labels