I am writing a PHP script that connects to a remove server using SSH. what I need to do is to check if a specific process is running or not so that I can terminate it. I am using the phpseclib. following code connects to the server and lists the processes but i am really stuck in getting the process id of each processes!
include('Net/SSH2.php');
$ssh = new Net_SSH2('192.168.1.1');
$ssh->login('username', 'password') or die("SSH Login failed");
$ps = $ssh->exec('ps -ef | grep ".php"');
echo $ps;
The output is :
root 32405 1 3 09:45 ? 00:03:30 php /afghanwiz/distributor1.php
root 32407 1 3 09:45 ? 00:03:33 php /afghanwiz/distributor2.php
I have tried to get the pid (here is 32405 and 32407) using exploding the lines and words but no success. Anyone has any idea of such an issue?