On Wed, Mar 17, 2010 at 12:47:23PM -0400, [email protected] wrote:
>It would be ideal if we could have a policy that would count processes
>that match and report that number rather than reporting whether or not the
>count is within a range. We could compare that number with a command
>policy that would script something like ps -ef|grep cf-execd$ |grep -v
>grep|wc -l. Bonus points if a policy can also compare the two numbers and
>report a difference. However, I can't think of a policy that would
>natively count the number processes.
I agree. This would basically be a generic built-in function, the sort
of which has been mentioned elsewhere... It is no different than other
basic "tools" already provided that provide integer values. In fact,
there is already a "countlinesmatching" function which is similar in
nature:
http://www.cfengine.org/manuals/cf3-reference.html#Function-countlinesmatching
Perhaps a countprocessesmatching function along the lines of:
countlinesmatching(pattern, type) returns type int.
where:
type => 'literal', 'regex', 'fullregex', to determine the type of matching.
pattern => variable behavior, depending on value of the 'type' argument:
'literal', basename of the process name is compared via strcmp()
'regex', basename of process is matched against a regex
'fullregex', entire processname and arguments are matched vs. regex
Function returns number of processes matching the pattern/type. A zero
value is returned if there are no processes matching.
For bonus opints, a third optional argument:
desired => (optional), desired number of processes.
If a 'desired' value is passed, and the number of processes matching is
*not* equal to this value, the number of matches is returned, but as a
negative value. (a bit of a kludge, I suppose)
--
Jesse Becker
NHGRI Linux support (Digicon Contractor)
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine