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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.