Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
 
Reply to this topicStart new topic
> Php Detirmine If Program Is Running, For kernel 2.6
gieltje
post Apr 11 2004, 02:41 PM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 2
Joined: 11-April 04
Member No.: 2,763



Hi all,

I had a php script for kernel 2.4 that printed up or down if a program was or was not running;

<?php
function checkk($daemon,$name) {
$ps ="ps ax | grep $daemon | wc -l";
$origps = exec($ps);
$minone = $origps-3;
if ($minone<1) {
$dataps = "<b><font color=red>DOWN</font></b>";
}
if ($minone==1) {
$dataps = "<b><font color=blue>Up</font></b>";
}
if ($minone>1) {
$dataps = "<b><font color=blue>Up</font></b>";
}
return $dataps;
}
echo checkk("q3ded","Q3ded server");
?>

But in kernel 2.6 it doesnt work, it just ad randum displays up or down wheter it is running or not.

Who has/can make a working script for 2.6?

Regards,

Michiel
Go to the top of the page
 
+Quote Post
hughesjr
post Apr 11 2004, 08:19 PM
Post #2


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151



What this script does is figure out how many processes are running that match the $daemon name .... (the number of lines) ...

Then for some reason it subtracts 3 from that number and if the result is < 1, it says down ... otherwise it says up.

(one result is going to be the grep command itself, that means that the logic is 3 other processes are named the $daemon 's name for everything that runs as a deamon).

It would seem to me that this logic is bogus reguardless of the kernel ... I have a redhat system with sendmail running ... and the command:

ps ax | grep sendmail | wc -l

equals 3

so :

3 - 3 = 0

which means sendmail is down ... but it is up.

What is your distro of linux?


--------------------
Johnny Hughes
hughesjr@linuxhelp.net
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
 
+Quote Post
gieltje
post Apr 12 2004, 04:38 AM
Post #3


Whats this Lie-nix Thing?
*

Group: Members
Posts: 2
Joined: 11-April 04
Member No.: 2,763



Debian Sid
Go to the top of the page
 
+Quote Post
Hemant
post Apr 12 2004, 07:52 PM
Post #4


RMS is my Hero
******

Group: Support Specialist
Posts: 782
Joined: 6-October 02
From: Trichy,INDIA
Member No.: 29



Yeah..there are two problems..in the code
1.Basically when you check for a service that is not running...let's say of name foo.

$ ps ax|grep foo|wc -l


this will return 1..becuase..for a process that has name foo ,there is only one process running..and that is..

grep foo


Another error in the program..is use of grep as we know grep by default searches..for all the matches..that contain..the pattern either as full word or as a substring.
so the output of this command will be

$ ps ax|grep init
...................init
..................xinit<all the xinit>
..................kdeinit<all the kdeinit processes>
..................grep init<just entered command>


but you intended to search for init only,.so only two line should be printed.With these modifications..your code will be....
CODE
<?php
function checkk($daemon,$name) {
$ps ="ps ax | grep -w $daemon | wc -l";
$origps = exec($ps);
$minone = $origps;
if ($minone>1) {
$dataps = "<b><font color=blue>Up</font></b>";
}
else
{
$dataps = "<b><font color=red>DOWN</font></b>";
}
return $dataps;
}
echo checkk("q3ded","Q3ded server");
?>

this should work...


--------------------
Hemant Kumar
user posted image
hemant@linuxhelp.net
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 24th October 2017 - 06:33 AM