LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-18-2014, 11:39 AM   #1
WasaProduction
LQ Newbie
 
Registered: May 2014
Posts: 4

Rep: Reputation: Disabled
Executing bash in browser, apache2


Hi Everyone
What im trying to achieve is to deploy some data of the system in a browser, using bash scripts for example
Code:
#!/bin/bash
hostname
uname
uname -o
But all I get is the same thing in plain text, how can I modify that code in order to deploy what those commands should deploy?, y already have seen some things like
Code:
echo "Content type: text/html"
but I am not really sure how to use that
Thanks!
 
Old 05-18-2014, 12:59 PM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
But all I get is the same thing in plain text, how can I modify that code in order to deploy what those commands should deploy?
Do you want to check, what those commands do in your script? If yes, just use debugging in your script i.e. just add set -vx below shebang and run the script again, as:
Code:
#!/bin/bash
set -vx
hostname
uname
uname -o
It will display the result of every command that is executing within the script, so you would be able to find what exactly those commands are doing.
 
Old 05-18-2014, 01:15 PM   #3
WasaProduction
LQ Newbie
 
Registered: May 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
I do know what they do, but what I´m trying to do here is to make them work in the browser by calling the script, but all that I can achieve is that the browser actually opens the script but only prints the commands not what they are supposed to do, for example the hostname displays "wasa" in the terminal, but when I run the script in the browser it prints "hostname".
Thanks.
 
Old 05-18-2014, 01:26 PM   #4
ndc85430
Member
 
Registered: Apr 2014
Distribution: Slackware
Posts: 92

Rep: Reputation: Disabled
The web server probably doesn't know how to run Bash scripts. I don't know if it's possible to do that with Apache, either. What you'll probably need to do is use something the server can deal with (e.g. PHP - see mod_php, I believe) to either run your script and provide the output, or to replace your script (if PHP, say, has functionality to replicate what you're doing with Bash).
 
1 members found this post helpful.
Old 05-18-2014, 01:27 PM   #5
ndc85430
Member
 
Registered: Apr 2014
Distribution: Slackware
Posts: 92

Rep: Reputation: Disabled
Hmm, perhaps I misunderstood what you want to do. Browsers don't execute Bash scripts, either.
 
Old 05-18-2014, 01:45 PM   #6
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Quote:
Hmm, perhaps I misunderstood what you want to do. Browsers don't execute Bash scripts, either.
Very true, but you were close when you mentioned PHP and the Apache Server.
You can use PHP to make system calls (system()) which would execute a bash script, you just have to designate variables to capture the output. Then you can have the web server dynamically construct the page and serve it.
It's a great beginners PHP project if anybody is interested in learning PHP/Apache administration
 
Old 05-18-2014, 01:49 PM   #7
WasaProduction
LQ Newbie
 
Registered: May 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Lightbulb

Actually I found this page -> http://www.yolinux.com/TUTORIALS/Lin...ellScript.html
That i think it may help to create this script, but im still having trouble in undestanding how it works. I noticed that it is using HTML but no really sure what does
Code:
/bin/cat << EOM
is suposed to do, and if it affects that my scripts are in /var/www/html
Thanks.
 
Old 05-18-2014, 01:57 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by ndc85430 View Post
The web server probably doesn't know how to run Bash scripts.
That indeed is not listed in a stock httpd configuration.


Quote:
Originally Posted by ndc85430 View Post
I don't know if it's possible to do that with Apache, either.
Yes, Apache can (just configure it to accept BASH scripts as valid CGI) but obviously there's languages that are traditionally or commonly used as CGI.


Quote:
Originally Posted by WasaProduction View Post
(..) what I´m trying to do here is to make them work in the browser by calling the script (..)
If there's no specific reason for using a browser (you haven't told us about BTW) then why not use SSH instead? As in 'ssh user@system some commands;'? (Also note that if your question is part of Something Completely Different you may run into commands that require more privileges than the user the web server runs as is allowed. If and once you've reached that stage please consider very carefully security-wise which replies you accept as as valid answer. The Devil's in the details, there's often multiple approaches and solutions, so please be clear and detailed in what you ask for.)
 
Old 05-18-2014, 02:16 PM   #9
WasaProduction
LQ Newbie
 
Registered: May 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
What im trying to acomplish here is something that a professor said that could be done, there is no point in using a browser, only finding if it is possible, and yes it is very insecure, everything im creating has all the permissions that i could give it and everyone can access them (fortunately im in a virtual machine). but it think that as it is shown in the page
Quote:
Actually I found this page -> http://www.yolinux.com/TUTORIALS/Lin...ellScript.html
there is a way and maybe there are not 100% bash commands and it have some HTML but if I can achive it lets go for it, but im new in this so i dont fully understand what they are doing there in order to apply it myself.
Thanks.

Last edited by WasaProduction; 05-18-2014 at 02:19 PM.
 
Old 05-18-2014, 02:35 PM   #10
ndc85430
Member
 
Registered: Apr 2014
Distribution: Slackware
Posts: 92

Rep: Reputation: Disabled
The link you posted is related to what unSpawn posted above about CGI. It looks like the scripts there are generating the response - some HTML with the contents of a file in it. The stuff between "/bin/cat << EOM" and "EOM" at the bottom of the script is known as a here document.
 
2 members found this post helpful.
  


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
PHP installed but not executing when in browser on CentOS server saxophonemaster Linux - Server 6 06-20-2012 11:53 PM
[SOLVED] BASH: service apache2 start => check apache2 response dragonetti Linux - Newbie 2 10-29-2011 11:01 AM
BASH -copy stdin to stdout (replace cat) (bash browser) gnashley Programming 4 07-21-2008 01:14 PM
Executing shell script with shell_exec from PHP5 on Apache2 gives timeout raven Programming 1 02-06-2008 02:04 AM
executing Bash Scripts c4nk Linux - General 3 03-11-2007 04:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:54 PM.

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