Forum: CFEngine Help
Subject: Re: help with commands - append date to file
Author: matt_garman
Link to topic: https://cfengine.com/forum/read.php?3,23912,23919#msg-23919
phnakarin Wrote:
-------------------------------------------------------
> You should probably use CFE touch => "true" to the
> file promise, if you'd to touch the file.
Can you elaborate on why I should use touch in addition to create? The
documentation says that "touch" just updates the timestamps on the file. But
in my example here, wouldn't appending to the file update the timestamps anyway?
> Anyhow, in order to use UNIX IO redirection, you
> have to run the command in shell. A contain body
> is an answer.
I suspected it was something like that. I'm assuming CFEngine must use some
kind of execv() (or similar) function call to run the command, and ">>" is a
shell function, so wouldn't make sense in a execv() context.
Anyway, just to help anyone else out that might have this problem, I believe
the example below is probably a cleaner way to achieve my goal... probably more
"cfengine idiomatic":
bundle agent test1
{
vars:
"testfile" string => "/tmp/test_plain";
files:
"${testfile}" -> "Some Person"
comment => "Make sure ${testfile} exists, and append a timestamp",
create => "true",
edit_line => append_if_no_line("${sys.date}");
}
Perhaps I'm missing something, but is there a builtin or cfengine_stdlib to
always append to a file? My understanding of what's available is that the line
will only be appended if it doesn't already exist. In my example here, the
timestamp ensures that the line will always be unique (unless run multiple
times per second)... but let's say that just for kicks I want to repeatedly
append "hello world" to a file. Is there a "nicer" way to do this other than
using IO redirection?
Thanks!
Matt
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine