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";  
}
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.