我如何在cfengine3中使用命令的输出

我想列出一个目录内容,并在其他地方使用结果:

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

 bundle agent test { vars: "my_result" string => execresult("/bin/ls /tmp/test/","noshell"); reports: ubuntu:: "Output is : $(my_result)"; } 

请参阅https://cfengine.com/manuals/cf3-solutions#Execresult-example

从版本3.3.0开始,可以使用lsdir()函数。

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

阅读更多: https : //cfengine.com/manuals/cf3-Reference#Function-lsdir