Forum: Cfengine Help Subject: copy file from A to B only if it is not present in C Author: erik Link to topic: https://cfengine.com/forum/read.php?3,21342,21342#msg-21342
Directories A, B and C have identical directory structure. I need to copy a file from directory A to directory B if the file does not exist in directory C. The only way I have found of doing this is with a separate perl script used in the file_select compound body: body common control { bundlesequence => { "test" }; } bundle agent test { files: "/B" copy_from => local_cp("/A"), depth_search => recurse("inf"), file_select => in_C; } body copy_from local_cp(src) { source => "$(src)"; } body depth_search recurse(d) { depth => "$(d)"; } body file_select in_C { exec_program => "/tmp/mycheck $(this.promiser) /A"; file_result => "exec_program"; } where mycheck is #!/usr/bin/perl if($ARGV[0] =~ m/$ARGV[1](.*)$/) { if (-f "C$1") { exit -1; } else { exit 0; } } this works, but I suspect it is an expensive solution for large directory trees, I would much rather have done something with ifvarclass and fileexists. /Erik _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine