CFE 语法错误
CFE syntax errors
尝试编写一个 cfengine3 承诺,它将获取整个目录并将其下移一级。
我已经使用我的政策中心来分发承诺,但我还没有将它折叠到我的活动中 promise.cf
这是承诺:
body common control
{
bundlesequence => { dirstructure };
}
#Find out by existance of directories if filesystem is old structure or new
#Set classes for each instance. If old, copy down one level.
#If new file system already, pat yourself on the back
bundle agent dirstructure
{
classes:
"oldFILEstructure"expression => isdir("/old/dir/structure/");
"newFILEstructure" expression => isdir("/new/dir/structure/");
reports:
oldFILEstructure::
"system has old file structure..";
newFILEstructure::
"system has new file structure..";
methods:
oldFILEstructure::
"migratedirectories" usebundle => movedirectories
}
bundle agent movedirectories
{
files:
"/new/dir/"
copy_from => local_cp ("/old/dir/structure/.");
depth_search => recurse ("inf");
}
我已将 this "isdir" source and this example 用于 local_cp,两者均来自 CFE,以此作为承诺的基础。
调用时,我得到以下错误输出,我试图找出原因。
:/var/cfengine/inputs/standalone# cf-agent --no-lock --inform --file ./file_structure.cf
./file_structure.cf:41:12: error: syntax error
depth_search => recurse ("inf");
^
./file_structure.cf:41:12: error: Expected promiser string, got 'depth_search'
depth_search => recurse ("inf");
^
./file_structure.cf:41:15: error: Expected ';', got '=>'
depth_search => recurse ("inf");
^
./file_structure.cf:41:23: error: Expected promiser string, got 'recurse'
depth_search => recurse ("inf");
^
./file_structure.cf:41:25: error: Expected ';', got '('
depth_search => recurse ("inf");
^
./file_structure.cf:41:31: error: Expected ';', got ')'
depth_search => recurse ("inf");
^
./file_structure.cf:41:32: error: Expected promiser string, got ';'
depth_search => recurse ("inf");
^
./file_structure.cf:42:1: error: Expected ';', got '}'
}
files:
"/new/dir/"
copy_from => local_cp ("/old/dir/structure/.");
depth_search => recurse ("inf");
}
您在 copy_from 行的末尾多了一个分号。
分号 ;
表示承诺的结束。尝试将 copy_from 行末尾的分号切换为逗号 ,
.
files:
"/new/dir/"
copy_from => local_cp ("/old/dir/structure/."),
depth_search => recurse ("inf");
}
此外,您可能需要查看 transformer
属性。
它可能适合也可能不适合您的情况。\
bundle agent example
{
files:
"/old/dir/structure" -> { "jira:EXAMPLE-1234" }
transformer => "/bin/mv /old/dir/structure /new/dir/structure",
comment => "The standard is to use the new location because x, y, z. Bad thing Q or U might happen if this is not managed properly.";
}
尝试编写一个 cfengine3 承诺,它将获取整个目录并将其下移一级。
我已经使用我的政策中心来分发承诺,但我还没有将它折叠到我的活动中 promise.cf
这是承诺:
body common control
{
bundlesequence => { dirstructure };
}
#Find out by existance of directories if filesystem is old structure or new
#Set classes for each instance. If old, copy down one level.
#If new file system already, pat yourself on the back
bundle agent dirstructure
{
classes:
"oldFILEstructure"expression => isdir("/old/dir/structure/");
"newFILEstructure" expression => isdir("/new/dir/structure/");
reports:
oldFILEstructure::
"system has old file structure..";
newFILEstructure::
"system has new file structure..";
methods:
oldFILEstructure::
"migratedirectories" usebundle => movedirectories
}
bundle agent movedirectories
{
files:
"/new/dir/"
copy_from => local_cp ("/old/dir/structure/.");
depth_search => recurse ("inf");
}
我已将 this "isdir" source and this example 用于 local_cp,两者均来自 CFE,以此作为承诺的基础。 调用时,我得到以下错误输出,我试图找出原因。
:/var/cfengine/inputs/standalone# cf-agent --no-lock --inform --file ./file_structure.cf
./file_structure.cf:41:12: error: syntax error
depth_search => recurse ("inf");
^
./file_structure.cf:41:12: error: Expected promiser string, got 'depth_search'
depth_search => recurse ("inf");
^
./file_structure.cf:41:15: error: Expected ';', got '=>'
depth_search => recurse ("inf");
^
./file_structure.cf:41:23: error: Expected promiser string, got 'recurse'
depth_search => recurse ("inf");
^
./file_structure.cf:41:25: error: Expected ';', got '('
depth_search => recurse ("inf");
^
./file_structure.cf:41:31: error: Expected ';', got ')'
depth_search => recurse ("inf");
^
./file_structure.cf:41:32: error: Expected promiser string, got ';'
depth_search => recurse ("inf");
^
./file_structure.cf:42:1: error: Expected ';', got '}'
}
files:
"/new/dir/"
copy_from => local_cp ("/old/dir/structure/.");
depth_search => recurse ("inf");
}
您在 copy_from 行的末尾多了一个分号。
分号 ;
表示承诺的结束。尝试将 copy_from 行末尾的分号切换为逗号 ,
.
files:
"/new/dir/"
copy_from => local_cp ("/old/dir/structure/."),
depth_search => recurse ("inf");
}
此外,您可能需要查看 transformer
属性。
它可能适合也可能不适合您的情况。\
bundle agent example
{
files:
"/old/dir/structure" -> { "jira:EXAMPLE-1234" }
transformer => "/bin/mv /old/dir/structure /new/dir/structure",
comment => "The standard is to use the new location because x, y, z. Bad thing Q or U might happen if this is not managed properly.";
}