Configuration-Management

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

  • September 28, 2012

我想列出目錄內容並在其他地方使用結果:

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

引用自:https://serverfault.com/questions/403337