How do I execute a bash script from a link on a web page? Is there any way to do this
Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
A web-browser is not supposed to allow such behaviour. However, it is a fairly simple task to write a script that allows you to do this without a web browser, if all you have is a list of downloadable scripts hosted on some web page.
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.
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!
Last edited by francoisrv; 03-09-2011 at 07:58 AM.
Reason: security notice
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
if wget $1 -O webscript.bash;
then
read -p 'want to execute script? [y|N]' -t10 -n1;
if [[ $REPLY == [Yy] ]]
then
bash webscript.bash;
fi
rm webscript.bash;
fi
#hold the terminal window open for a short while.
sleep 10;
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'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.