Forum: CFEngine Help Subject: filecopy, transform with grep. Author: davidlee Link to topic: https://cfengine.com/forum/read.php?3,22985,22985#msg-22985
(Using community edition version 3.1.4.) Given an existing small simple text file (a list of machine names) as source, I want to ensure that a variant of it can exist as the result file, with a particular line (my own hostname) removed. As a UNIX command this is easily done as: grep -v "remove_this_line" /path/to sourcefile > /path/to/resultfile In our context, sourcefile might itself change from time to time (say, a few months apart), hence my wanting to use cfengine to track sourcefile and maintain resultfile. (Because the line to be removed contains the machine's own hostname, I can use "$(sys.uqhost)" as the grep string.) So I naturally looked at "transformer" for files (section 7.1.18). But I was surprised to find that this doesn't support the redirecting of the transformed output into the resultfile. (I realise it would probably have to go into a temporary file, so that cfengine could see whether the real target actually needs updating from the previous run.) Surely this must be easy. But I cannot see how to do it. I have overlooked something mind-bogglingly simple or trivial? Any thoughts? Note that the update needs to happen not only if the sourcefile has been updated, but also if the targetfile is absent (typically at first-time installation). So, as a subsidiary problem, my attempts to adapt the "do_update" example didn't seem to cover the absence of targetfile (the '-v' output indicated that my "do_update" equivalent doesn't get set when targetfile is absent). _______________________________________________ Help-cfengine mailing list [email protected] https://cfengine.org/mailman/listinfo/help-cfengine
