Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to list a directory content and use the result somewhere else:

bundle agent test
{

   commands:
      "ls /tmp/test/";

    reports:
    ubuntu::
       "print output here for example";  
# or add it to a variable which is how I really want to use it.
 }
share|improve this question

2 Answers 2

up vote 11 down vote accepted
bundle agent test
{

    vars:
        "my_result" string => execresult("/bin/ls /tmp/test/","noshell");

    reports:
        ubuntu::
            "Output is : $(my_result)";  
}

See https://cfengine.com/manuals/cf3-solutions#Execresult-example

share|improve this answer
    
Works like a charm! Thanks! –  awsiv Jun 29 '12 at 10:30

As of version 3.3.0, you can use the lsdir() function instead.

vars:
  "result" slist => lsdir("/tmp/test", ".*", "false");

read more : https://cfengine.com/manuals/cf3-Reference#Function-lsdir

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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