On Mon, 18 Nov 2002 20:01:42 +0200, [EMAIL PROTECTED] (Octavian Rasnita) wrote:
>Thank you. > >Please tell me how can I verify if the process is running. Hi here is a script I've been experimenting with. It only reports whether the process is running or not, in this case apache. You can easily put a "system rcapache restart" (or whatever your httpd restart command is) where it reports apache not running. This script will detect multiple instances of itself, and will kill itself if invoked with the "k" switch. This method actually scans ps for the process name, but there are other methods possible, like finding apache's pid and storing it to a file, then checking for the existence of the pid, instead of the name. Anyways, for your examination, here it is. apache-monitor #################################################### #!/usr/bin/perl -w #just run it. The first time it starts the daemon. If you try to start #it #a second time, it gives an error msg. Run it with any commandline #argument, # like "k" will kill all instances of the script use strict; use IO::Handle; use Proc::ProcessTable; use Proc::Daemon; my $t1 = new Proc::ProcessTable; my @pids; my $pid; foreach my $p (@{$t1->table}){ if($p->cmndline =~ /apache-monitor/){ $pid = $p->pid; #print "$pid\n"; push(@pids,$pid); #unless $pid == $$; } } ################################################### if (exists $ARGV[0]) { foreach $pid (@pids){ print "killing pid $pid\n"; kill 9,$pid; } } #################################################### if ($#pids > 0) { print "@pids already running!\n"; exit; } #################################################### Proc::Daemon::Init; #open(LOG,">>/var/log/apache-monitor.log") or die $!; #when run as root open(LOG,">>/tmp/apache-monitor.log") or die $!; #for testing while (1){ my $ok =0; my $t = new Proc::ProcessTable; foreach my $p (@{$t->table}){ if($p->cmndline =~ /\/usr\/sbin\/httpd/){ print LOG time(),' ',$p->cmndline," already running!\n"; $ok=1;last; } } if ($ok == 0) {print LOG time(),' ',"failed!\n";} LOG->flush; sleep(15); } ########################################################## -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]