Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

I need a perl script to stop & start program

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
cc
Posts: 820
Joined: 2005-06-08 19:14

I need a perl script to stop & start program

#1 Post by cc »

hi

I need a perl script to stop & start program:


# stop PROGRAM

sh /home/ntop.sh stop


# start PROGRAM

sh /home/ntop.sh start


I'd like first stop the program and start it again using apache & browser.

kind regards
cc

lacek
Posts: 764
Joined: 2004-03-11 18:49
Location: Budapest, Hungary
Contact:

#2 Post by lacek »

Use the "system" function. You need to check the return value this way (this is a copy-paste from the 'perlfunc' manual page, which is your friend):

Code: Select all

system("sh /home/ntop.sh stop")
if ($? == -1) {
    print "failed to execute: $!\n";
} elsif ($? & 127) {
    printf "child died with signal %d, %s coredump\n",
        ($? & 127),  ($? & 128) ? 'with' : 'without';
} else {
    printf "child exited with value %d\n", $? >> 8;
}
However, you can register shell scripts as cgi scripts, so you can write your program in shell script as well...

cc
Posts: 820
Joined: 2005-06-08 19:14

#3 Post by cc »

thanks

I've written this script:

Code: Select all

#!/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 "</head>\n";
print "<body bgcolor='#c0c0d0'>\n";
print "<center>";
print "<p><br></p>";
print "<p><br></p>";

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";

print "</center>";
print "</body>";
print "</html>";
from command line it works well, but via browser I get:
Status: 0 ntop

in error log from apache I have:

[Thu Jul 21 22:50:54 2005] [error] [client 192.168.0.105] Permission denied

howto change rights to execute system "program" via browser ?
Last edited by cc on 2005-07-27 01:02, edited 5 times in total.

lacek
Posts: 764
Joined: 2004-03-11 18:49
Location: Budapest, Hungary
Contact:

#4 Post by lacek »

The web services are run by the www-data user. You need to make sure that this user has all the necessary permissions.

Post Reply