Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm somewhat new to Ubuntu Linux.

I need to run the shell script from a html code. As I read somewhere like using Apache2 to generate a html and somehow I've succeeded to run a sh file from html, but I'm unable to see the command prompt which executes the commands in the sh script. It's running may be as a daemon.

So can any body help me how to make it visible?

share|improve this question
add comment

3 Answers

This is a totally wrong approach. The HTML file does nothing, it is a Markup language, that instructs a browser how to show you different elements. What you need it is a PHP, ASP, CGI, etc script that uses the system's shell to run arbitrary commands.

share|improve this answer
    
thanks for the reply Frantique.. i've used 'CGI' only for this.... but unable to view the output... is there any way we can make the terminal visible..? –  suresh Sep 27 '12 at 3:46
add comment

When you run a shell script as CGI, which is what I believe you are doing (or trying to do), it is run from the apache or other web server daemon and its output isn't visible anywhere. You can redirect its output to a file, for example by replacing the original script with one that runs the script and saves the output:

#!/bin/bash
./original.sh | tee --append file-to-save-to

(You should probably also update your question to show what your objective is, in addition to the problem you have encountered.)

share|improve this answer
    
Thanks for the reply otus, my intention is to make some build system with graphical user interface... rather than typing commands to build some code(ex: like make xxxx etc.) i want to create HTML buttons to be clicked for building appropriate module. But by using CGI i'm unable to see the output for 'make' and even i'm unable to know whether it is running background or not.... so any one can help me regarding this.. is there any simple approach to follow other that what i'm using... thanks in advance –  suresh Sep 27 '12 at 4:07
    
outus, i've tried as u said to catch the output to some file, but the output is getting stored in the file only when every thing goes correct, if some error has occured (in the command mentioned in original.sh) then the file looks empty...:-( –  suresh Sep 27 '12 at 4:21
    
suresh, errors are written to stderr, so you'll need to redirect that to either a different file or the same: e.g. ./original.sh 2>&1 | tee --append file –  otus Sep 29 '12 at 12:31
    
thank you otus...:-) –  suresh Oct 1 '12 at 4:49
add comment

You can use perl-cgi do this. Take a look at

perl Packages. These modules will help you to make client connections.

Sample script using Net::telnet

use Net::Telnet ();
$t = new Net::Telnet (Timeout => 10,
                      Prompt => '/bash\$ $/');
$t->open("sparky");
$t->login($username, $passwd);
@lines = $t->cmd("who");
print @lines;

You can render the output of this program using cgi and display it in browser.

But the limitation of this would be like you cannot use a interactive shell to run your command.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.