How do I execute a bash script from a link on a web page? Is there any way to do this
I have a website that I can host and store my scripts. I want to be able to just click a link and have the computer that is clicking the link do one of two things:
1. open gnome-terminal and execute the script that is stored on the remote server, or 2. download the script, make it executable, and run the script locally 3. if I need a hybrid of the two, that's fine by me. I have searched possible answers and solutions using Google searches on bash scripts, executing php, html codes, and anything else I could think of with no success. Thanks in advance. |
In a word, no.
Could you imagine how dangerous it would be to even browse the Internet if it was possible for a link on a web page to start programs and run commands on your local machine? That is one of the reasons ActiveX (and IE in general, really) have been plagued with security issues. You could obviously put a link on the page to download the script, but executing it would be an exercise for the user of the local machine. |
Quote:
|
It's indeed insane at first view. Yet, supposing you have a special use case where this is secure (hard to imagine), then it is easy:
1- have your server (eg: a PHP script) sent the script with a “.bash” extension (for example) and an custom MIME type: “text/x-bash-script” 2- your browser will ask you what command to use for the “text/x-bash-script” type; point it at /bin/bash. Yves. |
use shell_exec
Kinda l8 reply but you could also do this from a PHP script:
<?=shell_exec('bash /path/to/my/script')?> This is to the extent that shell-interaction has not been disabled by your sysadmin If your exec function receives input (such as GET or POST), make sure you use the required validation and data sanitation and proper file permissions so nobody can do a bash injection or some other kinda bash bomb on you! |
You could create a Launcher, such as the one I did here.
The Launcher would run the script in a terminal. You would drag the web link from the browser and drop it on the Launcher. The launcher script would download the web link script and then execute it. The launcher script would be something like this (I did not debug this). Code:
#!/bin/bash |
using cgi with Apache could also do the trick if your bash script behaves differently according to the web context such as GET or POST. google 'apache cgi bash'
|
All times are GMT -5. The time now is 10:22 PM. |