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

如何在 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.
 }

答案1

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

答案2

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

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

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

相关内容