Menu

#131 PSStatus allow wildcard on process names

code_needs_review
open
nobody
General (14)
5
2013-10-29
2012-08-19
Anonymous
No

I needed to have the possibility of wildcard process names and changed the command for the plugin from "pidof" to "pgrep" with the appropriate arguments and a " | tail -1 " to get just 1 result as before.

Code change in /phpsysinfo/plugins/PSStatus/class.PSStatus.inc.php :

Line 67 ( function __construct switch case command )
****
ORIGINAL //CommonFunctions::executeProgram("pidof", "-s ".$process, $buffer, PSI_DEBUG);
CHANGED CommonFunctions::executeProgram("pgrep", "-x ".$process." | tail -1", $buffer, PSI_DEBUG);
****
pgrep allows for wildcard matching
-x = match exactly
| tail -1, only return the last PID

this means that in the PSStatus.config.php file you can do a wildcard search as follows:
****
define('PSI_PLUGIN_PSSTATUS_PROCESSES', 'mysqld, sshd, apache2, cron, ddclient.*');
*****
where the last process "ddclient" has ".*" appended to match any process whose name starts with ddclient
( I needed it in this case because ddclient's process name also has - sleep 20s appended and this changes constantly )

Hope this helps, I have no idea about compatibility of "pgrep" compared to "pidof", but this was at least useful to me.

Discussion

  • Mieczysław Nalewaj

    Try the simpler version:
    CommonFunctions::executeProgram("pgrep", "-n -x ".$process , $buffer,
    PSI_DEBUG);

     
  • Mieczysław Nalewaj

    Download pre 3.1.8 version from https://github.com/rk4an/phpsysinfo and test USE_REGEX option.