Forum Moderators: coopster

Message Too Old, No Replies

Check if Different Services are Running

         

Anyango

7:10 am on Mar 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello

Can we write something in PHP to find out if different services on the Linux machine are running, the three most important ones which i would run the script for, are,

httpd
Mysql
Bind (dns)

?

phparion

10:56 am on Mar 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



php has a function shell_exec() that you can use to execute linux commands e.g

$output = shell_exec('service httpd status');

//echo $output;

if service is running it will display "service httpd is running" otherwise "service httpd is stopped"

you can do the same for each service

Anyango

5:14 pm on Mar 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi phparion

Great tip, silly me i never thought about that. One thing though, for "service named status" it isnt showing any string, function shell_exec returns empty string for that whereas the same command when ran through shell outputs 6-7 lines. any idea why it is so?

phparion

7:26 am on Apr 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



"shell outputs 6-7 lines"

it should be single line whether the service is running or not running...

check if the service is installed on your server.. you should get exactly

SERVICE NAME IS RUNNING

SERVICE NAME IS NOT RUNNING / STOPPED

but no other thing.. and also make sure you are executing php page with root user (though not sure if privileges are necessary for this command

Anyango

6:37 pm on Apr 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi phparion

i would respectfuly have to disagree on that point, even if you run 'service named status' on ssh terminal directly, it returns 5-7 lines telling different things about named server and in the end it says service named is running.

phparion

1:05 pm on Apr 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you have the right to disagree.. however here is what I get always

[root@RHCEadmin ~]# service httpd status
httpd (pid 2122 2121 2120 2114 2113 2112 2111 2110 2097) is running...