Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Desktop
User Name
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.


  Search this Thread
Old 03-10-2010, 08:49 AM   #1
LQ Newbie
Registered: Mar 2010
Location: Newark, NJ
Distribution: Ubuntu, LinuxMint
Posts: 6

Rep: Reputation: 0
Exclamation 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.
Old 03-11-2010, 09:20 PM   #2
LQ Guru
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
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.
Old 03-22-2010, 09:48 AM   #3
LQ Newbie
Registered: Mar 2010
Posts: 8

Rep: Reputation: 1
Originally Posted by MS3FGX View Post
Could you imagine how dangerous it would be
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.
Old 03-22-2010, 10:29 AM   #4
Senior Member
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 63
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.

Old 03-09-2011, 08:56 AM   #5
LQ Newbie
Registered: Mar 2011
Posts: 2

Rep: Reputation: 0
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!

Last edited by francoisrv; 03-09-2011 at 08:58 AM. Reason: security notice
Old 03-10-2011, 10:56 AM   #6
Registered: Jun 2003
Location: Washington
Distribution: Fedora FC23, Raspbian, Ubuntu Precise via Chrome/Crouton
Posts: 361

Rep: Reputation: 43
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).

if wget $1 -O webscript.bash;
   read -p 'want to execute script? [y|N]' -t10 -n1;
   if [[ $REPLY == [Yy] ]]
      bash webscript.bash;
   rm webscript.bash;
#hold the terminal window open for a short while.
sleep 10;
Old 03-11-2011, 03:56 AM   #7
LQ Newbie
Registered: Mar 2011
Posts: 2

Rep: Reputation: 0
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'


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute a shell script from a simple html web page Shreerang Patwardhan Linux - Software 7 03-11-2010 12:12 PM
How do I execute a bash script from a link on a web page? Is there any way to do this digilifellc Linux - Desktop 5 03-10-2010 12:24 PM
Web query to execute commands and output it to a web page ! ashes_sheldon Linux - Newbie 1 05-08-2009 03:45 AM
Execute bash commands from web page solomage Linux - Software 1 10-07-2004 11:54 AM
execute command from web page FNC Programming 5 03-06-2003 07:17 PM > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 11:01 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration