1

In cfengine, I have a variable that is set to the output of a command. Let say variable myoutput is set to "hi world". How can I execute a command based on the contents of myoutput.

I would like to do something like this (sudo cfengine code):

bundle agent test
{

    vars:
        "myoutput" string => execresult("echo 'hi world';","noshell");

    commands:
        myoutput=="hi world"::
            "/usr/bin/php myaction.php";  
}
Daniel
  • 251
  • 3
  • 12

1 Answers1

1

There is a strcmp() function for that: https://cfengine.com/archive/manuals/cf3-Reference#Function-strcmp

Try this:

bundle agent test
{
vars:
    "expected" string => "hi world";
    "myoutput" string => execresult("/bin/echo 'hi world'","noshell");

classes:
"equal" expression => strcmp($(myoutput),$(expected));

reports:
  equal::
    "output is AS expected: $(myoutput)";
     # do other stuff                                                                                                                                     
}

This sets a class "equal" if the output of execresult() is the same as the expected output.

awsiv
  • 166
  • 11