Cfengine configuration directory

Defining a class if a string is found in a file

Relevant classes: any

If you want to define a class based on finding a string inside a file, then do NOT use 'editfiles', as it will define classes only if some editing took place on that file. What you have to do is to use 'ReturnsZero', but the tricky part is to use it properly, here is the format:
classes:

  # Old versions

   class_you_want_to_define = ( ReturnsZero("/bin/sh -c \'/bin/grep \"STRING TO LOOK FOR\" /file/to/look/in > /dev/null 2>&1\'") )

  # Better:

   class_you_want_to_define = ( ShellReturnsZero("/bin/grep \"STRING TO LOOK FOR\" /file/to/look/in > /dev/null 2>&1") )

Pay special attention to the use of single quotes, double quotes and the redirection of the stdout and stderr.
Back to documentation