LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-23-2005, 01:01 PM   #31
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872

Try add these debug lines before the first system() line :

Code:
print 'We are in '.$ENV{PWD}."\n";
print 'Is ntop.sh here ?';

if ( -e 'ntop.sh' ) {
    print "yes\n";
} else {
    die "no\nPlease put ntop.sh in the same dir where I am\n";
}

print "Now trying to execute ntop.sh stop...\n";
system('ntop.sh stop') or die "cannot stop ntop: $!";
 
Old 07-23-2005, 01:05 PM   #32
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
thanks, but still doesn't work:
Code:
# perl ntop.cgi
Content-Type: text/html; charset=ISO-8859-1

<html>
<head>
<title>ntop startup script</title>
<STYLE TYPE='text/css'>
h3 { color: red }
a { text-decoration: none; font: bold 14pt/16pt Ariel, serif }a:hover { color: red } /* when mouse is over link */</style>
</head>
<body bgcolor='#c0c0d0'>
<center><p><br></p><p><br></p>We are in /usr/local/www/cgi-bin
Is ntop.sh here ?yes
Now trying to execute ntop.sh stop...
<h1>Software error:</h1>
<pre>cannot stop ntop: No such file or directory at ntop.cgi line 44.</pre>
<p>
For help, please send mail to this site's webmaster, giving this error message
and the time and date of the error.

</p>
 
Old 07-23-2005, 01:18 PM   #33
hlyrad
Member
 
Registered: Jul 2005
Location: Ab Ca
Distribution: Redhat EL Sun Mac OSX FC 3.0 & 4.0
Posts: 44

Rep: Reputation: 15
What distribution are you running this on?? The perl script I wrote works as follows
Code:
#!/usr/bin/perl -w

use CGI::Carp qw(fatalsToBrowser);
use CGI;
my $query = new CGI;

print $query->header;
print "<html>\n";
print "<head>\n";
print "<title>ntop startup script</title>\n";
print "<STYLE TYPE='text/css'>\n";
print "h3 { color: red }\n";
print "a { text-decoration: none; font: bold 14pt/16pt Ariel, serif }";
print "a:hover { color: red } /* when mouse is over link */";
print "</style>\n";
print "</head>\n";
print "<body bgcolor='#c0c0d0'>\n";
print "<center>";
print "<p><br></p>";
print "<p><br></p>";

my $bb = `./ntop.sh stop` or die ($!);
sleep(5);
my $cc = `./ntop.sh start` or die ($!);
print "</body>";
print "</html>";
I created a simulated ntop.sh in the same directory as follows
Code:
#!/bin/bash

case "$1" in
start)
  # is it the first time we run ntop
echo "Starting ntop"
  ;;
stop)
echo "Stopping ntop"
  ;;
*)
  echo "Usage: `basename $0` {start|stop}" >&2
  exit 64
  ;;
esac

exit 0
Here is the output after running the script:


Code:
[root@myweb ntop]# ./newtop.cgi
Content-Type: text/html; charset=ISO-8859-1

<html>
<head>
<title>ntop startup script</title>
<STYLE TYPE='text/css'>
h3 { color: red }
a { text-decoration: none; font: bold 14pt/16pt Ariel, serif }a:hover { color: red } /* when mouse is over link */</style>
</head>
<body bgcolor='#c0c0d0'>
<center><p><br></p><p><br></p>Stopping ntop
Starting ntop
</body></html>[root@myweb ntop]#
Code:

Your not running SElinux are you? I would check the /var/log/messages for entries as follows

Jul 23 12:02:22 myweb kernel: audit(1122141742.771:0): avc: denied { search } for pid=6906 exe=/bin/bash dev=devpts ino=1 scontext=root:system_r:httpd_sys_script_t tcontext=user_u:object_r:devpts_t tclass=dir
Jul 23 12:02:22 myweb kernel: audit(1122141742.772:0): avc: denied { search } for pid=6906 exe=/bin/bash dev=devpts ino=1 scontext=root:system_r:httpd_sys_script_t tcontext=user_u:object_r:devpts_t tclass=dir

This indicates that SElinux does not allow execution of the ntop.sh script by httpd_sys_script_t tcontext

Also it might be Carp croaking your script before it has a chance to run.
Try commenting out the
Code:
 
BEGIN
{
use CGI::Carp qw(carpout);
my $errorlog = "/var/tmp/errorlog.txt";
open(LOG, ">$errorlog") or die("Unable to open $errorlog: $!\n");
print LOG "Errors:\n";
carpout(*LOG);
}
and rerun the script.
Sorry if this is a lot of dense text

Last edited by hlyrad; 07-23-2005 at 05:07 PM.
 
Old 07-23-2005, 03:22 PM   #34
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
thanks a lot !

# uname -a
FreeBSD bsd.domain.net 5.4-RELEASE FreeBSD 5.4-RELEASE #0: Sun May 8 10:21:06 UTC 2005 root@harlow.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386

I've tried your scripts and get
Code:
# perl ntop2.cgi
Content-Type: text/html; charset=ISO-8859-1

<html>
<head>
<title>ntop startup script</title>
<STYLE TYPE='text/css'>
h3 { color: red }
a { text-decoration: none; font: bold 14pt/16pt Ariel, serif }a:hover { color: red } /* when mouse is over link */</style>
</head>
<body bgcolor='#c0c0d0'>
<center><p><br></p><p><br></p>[Sat Jul 23 22:22:38 2005] ntop2.cgi: Can't exec "./ntop.sh": No such file or directory at ntop2.cgi line 22.
<h1>Software error:</h1>
<pre>No such file or directory at ntop2.cgi line 22.</pre>
<p>
For help, please send mail to this site's webmaster, giving this error message
and the time and date of the error.

</p>
[Sat Jul 23 22:22:38 2005] ntop2.cgi: No such file or directory at ntop2.cgi line 22.
 
Old 07-23-2005, 03:34 PM   #35
hlyrad
Member
 
Registered: Jul 2005
Location: Ab Ca
Distribution: Redhat EL Sun Mac OSX FC 3.0 & 4.0
Posts: 44

Rep: Reputation: 15
Remove the use CGI::Carp qw(fatalsToBrowser);
Make sure that both files are in the same directory. (I'm sure they are)
Change the relative path to fully qualified.
Try running the perl debugger but first comment out the
use CGI;
my $query = new CGI;
print $query->header;

type l -d ntop2.cgi
this opens the debugger
type s to step through each line of code.
Post your results please.
 
Old 07-23-2005, 04:02 PM   #36
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
# l -d ntop2.cgi
l: Command not found.

should I du
# perl -d ntop2.cgi
instead ?
 
Old 07-23-2005, 04:18 PM   #37
hlyrad
Member
 
Registered: Jul 2005
Location: Ab Ca
Distribution: Redhat EL Sun Mac OSX FC 3.0 & 4.0
Posts: 44

Rep: Reputation: 15
Sorry was on my way out. Yes perl -d is the debugger.
 
Old 07-23-2005, 04:41 PM   #38
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
never ending story !

Last edited by cccc; 07-23-2005 at 04:55 PM.
 
Old 07-23-2005, 04:45 PM   #39
hlyrad
Member
 
Registered: Jul 2005
Location: Ab Ca
Distribution: Redhat EL Sun Mac OSX FC 3.0 & 4.0
Posts: 44

Rep: Reputation: 15
No No No
Try running the perl debugger but first comment out the following
use CGI;
my $query = new CGI;
print $query->header;
Otherwise you get all the CGI stuff like you did
 
Old 07-23-2005, 04:59 PM   #40
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
cannot post the code:

You have included too many images in your signature or in your previous post. Please go back and correct the problem and then continue again.

Images include use of smilies, the vB code [img] tag and HTML <img> tags. The use of these is all subject to them being enabled by the administrator.
 
Old 07-23-2005, 05:06 PM   #41
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
Code:
# perl -d ntop2.cgi

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(ntop2.cgi:7):    print "<html>\n";
  DB<1> s
<html>
main::(ntop2.cgi:8):    print "<head>\n";
  DB<1> s
<head>
main::(ntop2.cgi:9):    print "<title>ntop startup script</title>\n";
  DB<1> s
<title>ntop startup script</title>
main::(ntop2.cgi:10):   print "<STYLE TYPE='text/css'>\n";
  DB<1> s
<STYLE TYPE='text/css'>
main::(ntop2.cgi:11):   print "h3 { color: red }\n";
  DB<1> s
h3 { color: red }
main::(ntop2.cgi:12):   print "a { text-decoration: none; font: bold 14pt/16pt Ariel, serif }";
  DB<1> s
main::(ntop2.cgi:13):   print "a:hover { color: red } /* when mouse is over link */";
  DB<1> a { text-decoration: none; font: bold 14pt/16pt Ariel, serif }s
main::(ntop2.cgi:14):   print "</style>\n";
  DB<1> a:hover { color: red } /* when mouse is over link */s
</style>
main::(ntop2.cgi:15):   print "</head>\n";
  DB<1> s
</head>
main::(ntop2.cgi:16):   print "<body bgcolor='#c0c0d0'>\n";
  DB<1> s
<body bgcolor='#c0c0d0'>
main::(ntop2.cgi:17):   print "<center>";
  DB<1> s
main::(ntop2.cgi:18):   print "<p><br></p>";
  DB<1> <center>s
main::(ntop2.cgi:19):   print "<p><br></p>";
  DB<1> <p><br></p>s
main::(ntop2.cgi:21):   my $bb = `./ntop.sh stop` or die ($!);
  DB<1> <p><br></p>s
Can't exec "./ntop.sh": No such file or directory at ntop2.cgi line 21.
 at ntop2.cgi line 21
No such file or directory at ntop2.cgi line 21.
 at ntop2.cgi line 21
Debugged program terminated.
 
Old 07-23-2005, 05:14 PM   #42
hlyrad
Member
 
Registered: Jul 2005
Location: Ab Ca
Distribution: Redhat EL Sun Mac OSX FC 3.0 & 4.0
Posts: 44

Rep: Reputation: 15
Quote:
Originally posted by cccc
Code:
main::(ntop2.cgi:21):   my $bb = `./ntop.sh stop` or die ($!);
Please change ./ntop.sh
to /path/to/ntop.sh

you could change to the ntop.sh directory and run
Code:
perl -e "`./ntop.sh`"
which should generate
Code:
Usage: ntop.sh {start|stop}
 
Old 07-23-2005, 05:36 PM   #43
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
I changed the path , but get this error:
Code:
# perl -e "`./ntop.sh`"
./ntop.sh: Command not found.
No code specified for -e.
 
Old 07-23-2005, 07:27 PM   #44
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
I solved this problem:

it needs following entry in sudoers

www bsd = NOPASSWD: /usr/local/www/cgi-bin/ntop/ntop.sh

and

this perl code does his job:
--------------------------------------------------------------------------------------------------------------
system `sh /usr/local/www/cgi-bin/ntop/ntop.sh stop`;
sleep(8);
my $start = system `sh /usr/local/www/cgi-bin/ntop/ntop.sh start &` or die "cannot start ntop: $!";
print "Status: ",$start,"\n";
--------------------------------------------------------------------------------------------------------------

I can stop & start ntop via browser !

greetings
cccc

Last edited by cccc; 07-26-2005 at 08:04 PM.
 
  


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
auditd outputting errors at service start & stop cdhgee Fedora 8 08-08-2005 01:22 PM
howto start a perl script only from tuesday to friday at 8.00 am ? cccc Linux - Newbie 4 03-19-2005 04:23 AM
Perl Script Program (need) : SpamAssassin-ClamAV-Procmail-Howto cyberjames Slackware 8 01-27-2005 11:53 AM
How to Call a C program from Perl CGI Script anoop_cn Programming 1 05-11-2004 04:37 PM
Start Program Script Cafrow Linux - Newbie 1 08-17-2003 04:26 AM

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

All times are GMT -5. The time now is 09:29 AM.

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