Linux - NewbieThis 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
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.
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
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.
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.
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).
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
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.
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
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
(..) 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.)
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.