LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   get a status output (https://www.linuxquestions.org/questions/programming-9/get-a-status-output-347256/)

cccc 07-27-2005 07:33 AM

get a status output
 
hi

I've this perl script:
Code:

#!/usr/bin/perl -w

use strict;
use warnings;
use CGI;
my $query = new CGI;
use CGI::Carp qw(fatalsToBrowser);
my $process = "ntop";

print $query->header;
print "<html>\n";
print "<head>\n";
print "<title>stop ntop</title>\n";
print "</head>\n";
print "<body bgcolor='#c0c0d0'>\n";
print "<center>";

my $return = 'ps -eaf |grep $process |grep -v grep';

my $stop = '/usr/local/bin/sudo /usr/local/www/cgi-bin/ntop/ntop.sh stop &';
system ($stop) or die "... ";

if ($stop == -1) {
    print "failed to execute: $!\n";
} elsif ($stop & 127) {
    printf "ntop died with signal %d, %s coredump\n",
        ($stop & 127),  ($stop & 128) ? 'with' : 'without';
} else {
    printf "ntop exited with value %d\n", $stop >> 8;
}

print "<font face=\"arial,helvetica\" size=2 color=\"#006600\">status:</font> ",$stop,"<br><br>\n";
print "</center>";
print "</body>";
print "</html>";


howto change it to get the output status in the browser:

"ntop is not running"

or

"ntop was killed"

kind regards
cccc

Matir 07-27-2005 02:30 PM

At what point do you want it to display that?

cccc 07-27-2005 03:47 PM

for example:

ntop was killed with...

or

ntop exited with value...

Matir 07-27-2005 03:50 PM

Isn't that already in there?

cccc 07-27-2005 04:10 PM

No, I get:
Code:

Software error:

...  at /usr/local/www/cgi-bin/ntop/bb.cgi line 21.


Matir 07-27-2005 04:20 PM

And you didn't think to mention that in your original question?

Does it really just show ..., or is there more detail?

cccc 07-27-2005 04:30 PM

no, you're completely right !

I'm looking for a output solution, if I have like in my first or like in the second question,
I'll be happy.

greetings
cccc

Matir 07-27-2005 04:39 PM

Ah, wait, I see, you intentionall just output "...". Nice error message. Very microsoftesque. :)

You need to (I think) remove the & from the end of your my $stop = ... line.

cccc 07-27-2005 05:09 PM

I changed to:
Code:

my $return = 'ps -eaf |grep $process |grep -v grep';

my $stop = '/usr/local/bin/sudo /usr/local/www/cgi-bin/ntop/ntop.sh stop';
system ($stop) or die "cannot stop ntop: $!";

if ($stop == -1) {
    print "failed to execute: $!\n";
} elsif ($stop & 127) {
    printf "ntop died with signal %d, %s coredump\n",
        ($stop & 127),  ($stop & 128) ? 'with' : 'without';
} else {
    printf "ntop exited with value %d\n", $stop >> 8;
}

but still get this error message.

chrism01 07-28-2005 01:59 AM

If you use backquotes around the cmd instead of single quotes, you'll get the returned text in $stop.

cccc 07-28-2005 04:35 PM

Backquotes are little bit dangerous
The expression within the backticks is executed upon assignment, and the $stop variable will hold the output of the expression.
Later, when I try to use
system($stop)
it would try to execute all that mess the ntop.sh program printed out.
I cannot take the output of ntop, and feed it back to system!

Matir 07-28-2005 04:37 PM

Then don't execute it through system(). Your system() call is failing, obviously.

cccc 07-28-2005 05:33 PM

Yes, you're completely right.

but how can I stop in other way ?

or is it:
Code:

system '/usr/local/bin/sudo /usr/local/www/cgi-bin/ntop/ntop.sh stop'  and die "... ";
a solution ?


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