LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-27-2005, 07:33 AM   #1
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Rep: Reputation: 51
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

Last edited by cccc; 07-27-2005 at 04:26 PM.
 
Old 07-27-2005, 02:30 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
At what point do you want it to display that?
 
Old 07-27-2005, 03:47 PM   #3
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
for example:

ntop was killed with...

or

ntop exited with value...
 
Old 07-27-2005, 03:50 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Isn't that already in there?
 
Old 07-27-2005, 04:10 PM   #5
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
No, I get:
Code:
Software error:

...  at /usr/local/www/cgi-bin/ntop/bb.cgi line 21.
 
Old 07-27-2005, 04:20 PM   #6
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
And you didn't think to mention that in your original question?

Does it really just show ..., or is there more detail?
 
Old 07-27-2005, 04:30 PM   #7
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
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
 
Old 07-27-2005, 04:39 PM   #8
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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.
 
Old 07-27-2005, 05:09 PM   #9
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
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.
 
Old 07-28-2005, 01:59 AM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If you use backquotes around the cmd instead of single quotes, you'll get the returned text in $stop.
 
Old 07-28-2005, 04:35 PM   #11
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
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!
 
Old 07-28-2005, 04:37 PM   #12
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Then don't execute it through system(). Your system() call is failing, obviously.
 
Old 07-28-2005, 05:33 PM   #13
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
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 ?
 
  


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
No output through SPDIf, but analog works. How do I get output through SPDIF? seanwnz Linux - General 11 11-08-2007 11:24 AM
Status mmmm LQ Suggestions & Feedback 2 06-25-2005 02:35 PM
bind status gubak Linux - Newbie 4 07-23-2004 12:25 AM
Via AC'97 5.1 Optical Output or Audigy 4.1 Output Nza Fedora 3 06-01-2004 07:49 AM
the sound gives output when using mic but no output when run a music file medo Debian 0 04-19-2004 07:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:18 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