ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I assume that what you want to do is allow the user(In reallity the user apache is running under) to stop and start your service?
If this is the case you must give the apache user rights to execute the script.
I use this script via apache/web browser to restart mysql on the same system.
#!/usr/bin/perl
use CGI;
my $query = new CGI;
print $query->header;
print "<html>\n";
print "<head>\n";
print "<title>Repair</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>";
`mysqladmin -u flush -preload flush-tables`;
`mysqladmin -u flush -preload shutdown`;
system "mysqld_safe --log &";
print "</center>";
print "</body>";
print "</html>";
I changed the directory and the script, but now I get following error from command line:
Code:
# perl ntop3.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><h1>Software error:</h1>
<pre>No such file or directory at ntop3.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>
[Thu Jul 21 23:19:15 2005] ntop3.cgi: No such file or directory at ntop3.cgi line 22.
the new script is:
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 = system("/usr/local/www/cgi-bin/ntop/ntop.sh stop") or die ($!);
sleep(5);
$cc = system("/usr/local/www/cgi-bin/ntop/ntop.sh start &") or die ($!);
print "</body>";
print "</html>";
exit($cc);
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 = `/usr/local/www/cgi-bin/ntop/ntop.sh stop` or die ($!);
sleep(5);
my $cc = `/usr/local/www/cgi-bin/ntop/ntop.sh start` or die ($!);
print "</body>";
print "</html>";
You were not checking the return values of $bb or $cc so just using the `` ticks to encapsulate was better.
In fact you could just do
`/usr/local/www/cgi-bin/ntop/ntop.sh stop` or die ($!);
sleep(5);
`/usr/local/www/cgi-bin/ntop/ntop.sh start` or die ($!);
and be done with it
No need to exit($cc)
Background the /usr/local/www/cgi-bin/ntop/ntop.sh start process depends on your script.
thanks a lot, I changed the script, but now I get this error from command line:
Code:
# perl ntop3.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><h1>Software error:</h1>
<pre>No such file or directory at ntop3.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>
[Fri Jul 22 00:54:44 2005] ntop3.cgi: No such file or directory at ntop3.cgi line 22.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.