Operating System - HP-UX
1748202 Members
3118 Online
108759 Solutions
New Discussion юеВ

Re: I need a perl script to stop and start program

 
SOLVED
Go to solution
'chris'
Super Advisor

I need a perl script to stop and start program

hi

I need a perl script to stop and 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
chris

14 REPLIES 14
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: I need a perl script to stop and start program

perl -e '$cc = system("/home/ntop.sh start"); exit($cc);'

I trust you can figure out the stop program.
If it ain't broke, I can fix that.
'chris'
Super Advisor

Re: I need a perl script to stop and start program

thanks,

I've written following perl script:

----------------------------------------------------------
#!/usr/bin/perl -w

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

$bb = system("/home/ntop.sh stop &");

exit($bb);

$cc = system("/home/ntop.sh start &");

exit($cc);
----------------------------------------------------------


if execute it from command line:

# perl ntop.cgi

then ntop starts,

but via browser, script be executed without errors, but ntop won't start.


# chown www ntop.cgi

doesn't help !

kind regards
chris

A. Clay Stephenson
Acclaimed Contributor

Re: I need a perl script to stop and start program

#!/usr/bin/perl -w

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

$bb = system("/home/ntop.sh stop &");

exit($bb); #### This exit terminate the program!!! Nothing past this point is done

$cc = system("/home/ntop.sh start &");

exit($cc);
-----------------------------------------

You made thimgs complicated using the & to stop in background.

Change to this:

#!/usr/bin/perl -w

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

my $bb = system("/home/ntop.sh stop");
sleep(10);
$cc = system("/home/ntop.sh start &");
exit($cc);

or this:
#!/usr/bin/perl -w

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

my $bb = system("/home/ntop.sh stop &");
wait; # wait for background task to finish
$cc = system("/home/ntop.sh start &");
exit($cc);

If it ain't broke, I can fix that.
'chris'
Super Advisor

Re: I need a perl script to stop and start program

thanks,
---------------------------------------------------------------------------------------
#!/usr/bin/perl -w

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

print $query->header;
print "\n";
print "\n";
print "Repair\n";
print "\n";
print "\n";
print "\n";
print "
";
print "


";
print "


";

my $bb = system("/home/ntop.sh stop");
sleep(5);
$cc = system("/home/ntop.sh start &");

print "";
print "";

exit($cc);
---------------------------------------------------------------------------------------

it works excellent from command line,
but it it doesn't start ntop via browser.

what's wrong ?
A. Clay Stephenson
Acclaimed Contributor

Re: I need a perl script to stop and start program

Add a
print "Status: ",$cc,"\n";

After the system call. You should at least then see the exit status. I suspect you are missing environment variables or ntop expects a tty device as stdin. Put probes that write to a file in your ntop.sh script.

If it ain't broke, I can fix that.
'chris'
Super Advisor

Re: I need a perl script to stop and start program

I get the output:

Status: 0 ntop

I think the www user has no rights
to execute "system" via browser,
because I have in the Apache error log:

[Thu Jul 21 23:43:54 2005] [error] [client 192.168.0.105] Permission denied

do you know howto change that ?

A. Clay Stephenson
Acclaimed Contributor

Re: I need a perl script to stop and start program

Do something like "ls -l /etc" inside your system command as a test.
If it ain't broke, I can fix that.
'chris'
Super Advisor

Re: I need a perl script to stop and start program

# ls -l /etc
total 602
-rw-r--r-- 1 root wheel 32 Jul 19 12:55 .directory
drwxr-xr-x 3 root wheel 512 Jul 18 22:54 .java
drwxr-xr-x 2 root wheel 512 Jul 20 23:02 X11
lrwxrwxrwx 1 root wheel 12 Jul 15 23:38 aliases -> mail/aliases
-rw-r--r-- 1 root wheel 65536 Jul 18 19:04 aliases.db
-rw-r--r-- 1 root wheel 209 May 8 09:05 amd.map
-rw-r--r-- 1 root wheel 1234 May 8 09:05 apmd.conf
-rw-r--r-- 1 root wheel 231 May 8 09:05 auth.conf
drwxr-xr-x 2 root wheel 512 Jul 15 23:38 bluetooth
-rw-r--r-- 1 root wheel 737 May 8 09:05 crontab
-rw-r--r-- 1 root wheel 108 May 8 09:05 csh.cshrc
-rw-r--r-- 1 root wheel 481 May 8 09:05 csh.login
-rw-r--r-- 1 root wheel 110 May 8 09:05 csh.logout
drwxr-xr-x 2 root wheel 512 Jul 15 23:38 defaults
-rw-r--r-- 1 root wheel 4846 May 8 09:05 devd.conf
-rw-r--r-- 1 root wheel 2071 May 8 09:05 devfs.conf
-rw-r--r-- 1 root wheel 267 May 8 09:05 dhclient.conf
-rw-r--r-- 1 root wheel 6621 May 8 09:05 disktab
-rw-rw-r-- 1 root operator 0 May 8 09:05 dumpdates
-rw-r--r-- 1 root wheel 142 May 8 09:05 fbtab
-rw-r--r-- 1 root wheel 391 Jul 15 23:50 fstab
-rw-r--r-- 1 root wheel 245 May 8 09:05 ftpusers
-rw-r--r-- 1 root wheel 5904 May 8 09:05 gettytab
drwxr-xr-x 2 root wheel 512 Jul 15 23:38 gnats
-rw-r--r-- 1 root wheel 489 Jul 16 15:09 group
-rw-r--r-- 1 root wheel 60 Jul 15 22:29 host.conf
-rw-r--r-- 1 root wheel 146 Jul 20 21:25 hosts
-rw-r--r-- 1 root wheel 3237 Jul 21 01:39 hosts.allow
-rw-r--r-- 1 root wheel 111 May 8 09:05 hosts.equiv
-rw-r--r-- 1 root wheel 99 May 8 09:05 hosts.lpd
-rw-r--r-- 1 root wheel 5319 May 8 09:05 inetd.conf
drwx------ 2 root wheel 512 Jul 15 23:38 isdn
-rw-r--r-- 1 root wheel 837 May 8 09:03 localtime
-rw-r--r-- 1 root wheel 619 May 8 09:05 locate.rc
-rw-r--r-- 1 root wheel 1847 May 8 09:05 login.access
-rw-r--r-- 1 root wheel 6522 May 8 09:05 login.conf
-rw-r--r-- 1 root wheel 65536 May 8 09:05 login.conf.db
-rw-r--r-- 1 root wheel 564 May 8 09:05 mac.conf
drwxr-xr-x 2 root wheel 512 Jul 17 12:51 mail
-rw-r--r-- 1 root wheel 106 May 8 09:05 mail.rc
-rw-r--r-- 1 root wheel 91 Jul 18 19:09 make.conf
-rw-r--r-- 1 root wheel 0 Jul 16 15:20 make.conf.bak
-rw-r--r-- 1 root wheel 1087 Jul 16 15:27 manpath.config
-rw-r--r-- 1 root wheel 946 Jul 16 15:20 manpath.config.bak
-rw------- 1 root wheel 1845 Jul 21 00:20 master.passwd
-rw-r--r-- 1 root wheel 1114 Jul 15 22:29 motd
drwxr-xr-x 2 root wheel 512 Jul 15 23:38 mtree
lrwxrwxrwx 1 root wheel 23 Jul 15 23:38 namedb -> ../var/named/etc/namedb
-rw-r--r-- 1 root wheel 783 May 8 09:05 netconfig
-rwxr-xr-x 1 root wheel 2362 May 8 09:05 netstart
-rw-r--r-- 1 root wheel 13696 May 8 09:05 network.subr
-rw-r--r-- 1 root wheel 365 May 8 09:05 networks
-rw-r--r-- 1 root wheel 1937 May 8 09:05 newsyslog.conf
-rw------- 1 root wheel 1701 May 8 09:05 nsmb.conf
-rw-r--r-- 1 root wheel 113 Jul 15 22:29 nsswitch.conf
drwx------ 2 root wheel 512 May 8 09:00 ntp
-rw------- 1 root wheel 432 May 8 09:05 opieaccess
-rw-r--r-- 1 root wheel 0 Jul 15 22:36 opiekeys
drwxr-xr-x 2 root wheel 512 Jul 15 23:38 pam.d
-rw-r--r-- 1 root wheel 1607 Jul 21 00:20 passwd
-rwxr-xr-x 1 root wheel 5814 May 8 09:05 pccard_ether
drwxr-xr-x 6 root wheel 512 Jul 15 23:38 periodic
-rw-r--r-- 1 root wheel 177 Jul 18 19:22 periodic.conf
-rw-r--r-- 1 root wheel 3567 May 8 09:05 pf.conf
-rw-r--r-- 1 root wheel 22556 May 8 09:05 pf.os
-rw-r--r-- 1 root wheel 293 May 8 09:05 phones
drwxr-xr-x 2 root wheel 512 Jul 15 23:38 ppp
-rw-r--r-- 1 root wheel 2058 May 8 09:05 printcap
-rw-r--r-- 1 root wheel 619 May 8 09:05 profile
-rw-r--r-- 1 root wheel 5807 May 8 09:05 protocols
-rw-r--r-- 1 root wheel 40960 Jul 21 00:20 pwd.db
-rw-r--r-- 1 root wheel 2716 May 8 09:05 rc
-rw-r--r-- 1 root wheel 5298 May 8 09:05 rc.bsdextended
-rw-r--r-- 1 root wheel 942 Jul 20 21:33 rc.conf
-rw-r--r-- 1 root wheel 1114 Jul 20 21:25 rc.conf~
drwxr-xr-x 2 root wheel 2560 Jul 15 23:38 rc.d
-rw-r--r-- 1 root wheel 9569 May 8 09:05 rc.firewall
-rw-r--r-- 1 root wheel 8905 May 8 09:05 rc.firewall6
-rwxr-xr-x 1 root wheel 2165 May 8 09:05 rc.resume
-rw-r--r-- 1 root wheel 5785 May 8 09:05 rc.sendmail
-rw-r--r-- 1 root wheel 3211 May 8 09:05 rc.shutdown
-rw-r--r-- 1 root wheel 30905 May 8 09:05 rc.subr
-rwxr-xr-x 1 root wheel 2209 May 8 09:05 rc.suspend
-rw-r--r-- 1 root wheel 2392 May 8 09:05 remote
-rw-r--r-- 1 root wheel 42 Jul 20 21:25 resolv.conf
lrwxrwxrwx 1 root wheel 13 Jul 15 23:38 rmt -> /usr/sbin/rmt
-rw-r--r-- 1 root wheel 1674 May 8 09:05 rpc
-rw-r--r-- 1 root wheel 73410 May 8 09:05 services
-rw-r--r-- 1 root wheel 237 Jul 16 00:04 shells
drwxr-xr-x 2 root wheel 512 May 8 09:00 skel
-rw------- 1 root wheel 40960 Jul 21 00:20 spwd.db
drwxr-xr-x 2 root wheel 512 Jul 15 22:34 ssh
drwxr-xr-x 2 root wheel 512 Jul 15 23:38 ssl
-rw-r--r-- 1 root wheel 367 May 8 09:05 sysctl.conf
-rw-r--r-- 1 root wheel 1339 May 8 09:05 syslog.conf
lrwxrwxrwx 1 root wheel 23 Jul 15 23:38 termcap -> /usr/share/misc/termcap
-rw-r--r-- 1 root wheel 13 Jul 20 22:48 timezone
-rw-r--r-- 1 root wheel 7658 May 8 09:05 ttys
-rw-r--r-- 1 root wheel 2032 May 8 09:05 usbd.conf
-r--r--r-- 1 root wheel 0 Jul 15 23:42 wall_cmos_clock

A. Clay Stephenson
Acclaimed Contributor

Re: I need a perl script to stop and start program

Okay, that's rather convincing data that this is not a simple permission problem. Start probing your ntop.sh shell and redirect both stderr and stdout to a logfile.
If it ain't broke, I can fix that.