help-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: non-convergent file edit?


From: rader
Subject: Re: non-convergent file edit?
Date: Tue, 16 Mar 2004 18:40:05 -0600

 > On Tue, 16 Mar 2004 rader@ginseng.hep.wisc.edu wrote:
 > > That said--my apologies in advance for being dense!--but I just
 > > don't see how...
 > > 
 > >  editfiles:
 > >    { /etc/motd 
 > >        ReplaceOnce "year is [[:digit:]]{4}" With "year is $(year)" }
 > > 
 > > ...could be unpredictable or "add extra things" to /etc/motd.
 
 > From: Eric Sorenson
 > I think the question is, how would you implement this so that it
 > is idempotent?  

...at first glance, by calling regexec() once per line instead of
iterating along the whole line, or something like that.   (See block
starting at line 1447 of src/item-ext.c)

 > How does cfengine know between invocations that 
 > "last time" we did it, so "this time" we mustn't?

"Last time" vs "this time" isn't an issue if you trigger ReplaceOnce
with a define= class.  Or, think of it this way: "every time".
Doesn't ReplaceAll behave the same way?

 > What should it do if I manually added a line in my motd that said "year is
 > 2004", and then ran cfengine? 

It would sub "year is 2004" with "year is 2004", of course!  =:)

 > Apologies if my one-note refrain is getting tiresome, 

Naw, I'm the one pickin' the fight.

 > but if you want a file's
 > contents to converge, and not change unless you really mean it, put it in a
 > 'copy:' section from your master server, specify 'type=checksum'  and then
 > never change the original... Problem solved :-)

Different problem?  What I what/have done to have cfengine update
widely differing /etc/motd files denoting the last time it's done
some updating...

 shellcommands:
   update_motd::
     "/bin/mv /etc/motd /etc/motd.OLD &&
      /bin/cat /etc/motd.OLD | /usr/bin/perl -ne 's/UW-HEP 
\d{2}\w{3}\d{2}/UW-HEP $(date_stamp)/;print' > /etc/motd &&
      /bin/rm /etc/motd.OLD &&
      /bin/chmod 444 /etc/motd"

(...where $(date_stamp) comes from an external module.)

steve 
- - - 
systems & network guy
high energy physics
university of wisconsin





reply via email to

[Prev in Thread] Current Thread [Next in Thread]