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

Notices


Reply
  Search this Thread
Old 03-10-2010, 07:49 AM   #1
digilifellc
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, 08:20 PM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
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, 08:48 AM   #3
meingbg
LQ Newbie
 
Registered: Mar 2010
Posts: 8

Rep: Reputation: 1
Quote:
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, 09:29 AM   #4
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
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.
 
Old 03-09-2011, 07:56 AM   #5
francoisrv
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 07:58 AM. Reason: security notice
 
Old 03-10-2011, 09:56 AM   #6
pwalden
Member
 
Registered: Jun 2003
Location: Washington
Distribution: Raspbian, Ubuntu, Chrome/Crouton
Posts: 374

Rep: Reputation: 50
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
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;
 
Old 03-11-2011, 02:56 AM   #7
francoisrv
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'
 
  


Reply



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 11:12 AM
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 11:24 AM
Web query to execute commands and output it to a web page ! ashes_sheldon Linux - Newbie 1 05-08-2009 02:45 AM
Execute bash commands from web page solomage Linux - Software 1 10-07-2004 10:54 AM
execute command from web page FNC Programming 5 03-06-2003 06:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 05:59 AM.

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