I have file1 and file3 in my directory and when cfengine creates file2 I'd like it to report that.
My test script below reports creating file2 and file3 most likely because report_file class is set when file2 is created and it stays that way.
How do I get it to report only the file it creates?
#== Start
body common control {
bundlesequence => { "mybundle" };
inputs => {
"/var/cfengine/inputs/
def.cf",
};
}
bundle agent mybundle {
vars:
"myList" slist => { "file1", "file2", "file3" };
methods:
"List Loop" usebundle => list_loop(${myList});
}
bundle agent list_loop(fileName) {
classes:
"hasfile" expression =>
returnszero("/bin/ls ${fileName}", "noshell");
commands:
!hasfile::
"/bin/touch ${fileName}"
classes => if_repaired(report_file);
reports:
report_file::
"New file ${fileName}";
}
#== End
file1
/bin/ls: cannot access file2: No such file or directory
2014-07-14T15:16:30-0700 info: /default/mybundle/methods/'List Loop'/default/list_loop/commands/'/bin/touch file2'[0]: Executing 'no timeout' ... '/bin/touch file2'
2014-07-14T15:16:30-0700 info: /default/mybundle/methods/'List Loop'/default/list_loop/commands/'/bin/touch file2'[0]: Completed execution of '/bin/touch file2'
R: New file file2
file3
R: New file file3
[root/ tmp]#
Thanks,
-- Peter