help-cfengine
[Top][All Lists]
Advanced

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

ReplaceLinesMatchingField working at all? (was: Re: editfiles problem -


From: Sven Mueller
Subject: ReplaceLinesMatchingField working at all? (was: Re: editfiles problem - revisited - Still nobody having an idea what goes wrong?)
Date: Fri, 03 Sep 2004 23:58:14 +0200
User-agent: Thunderbird 0.7.3 (Windows/20040803)

Tod Oace [u] wrote on 03/09/2004 22:46:

On Sep 3, 2004, at 13:12, Sven Mueller wrote:


Still nobody having an idea of how to solve my problem?


How about something like this:

{ /etc/passwd
        BeginGroupIfNoSuchLine "test::::::"
                DeleteLinesMatching "^test:.*$"
                Append "test::::::"
        EndGroup
        DefineClasses "restart_whatever"
}

Hmm, that should indeed work. But it is still error-prone because the line which should be inserted (as replacement if needed) still needs to be repeated character for character. That could be avoided by setting one or more variables and using them instead. But setting 100 variables and then repeating 5 lines a hundred times isn't really effective either. The most effective way would of course be to list the lines that (might) need to be replaced in a file of their own, and using "ForEachLineIn" on that file, instead of using the "SetLine" directive. But that doesn't work either.

*** As it seems, ReplaceLinesMatchingField seems not to work at all. ***

I just tried that approach:
cfagent.conf:
---- cut here ----
control:
        ActionSequence = ( editfiles )

editfiles:
        { /tmp/aliases
                ReplaceLinesMatchingField 1
                ForEachLineIn "/tmp/newaliases"
                        AppendIfNoLineMatching "ThisLine"
                EndLoop
                DefineClasses "edited"
        }

alerts:
        edited::
                "File was edited"
---- cut here ----
/tmp/newaliases:
---- cut here ----
user1:xx
---- cut here ----
/tmp/aliases before cfagent run:
---- cut here ----
user1:xxxx
user2:xxxx
---- cut here ----
/tmp/aliases after cfagent run:
---- cut here ----
user1:xxxx
user2:xxxx
user1:xx
---- cut here ----

cu,
sven

In short my problem was that I _need_ to restart a program if I changed it's config file. But for various reasons, I have to avoid restarting it, if I didn't change it.

The only way I have come up with is using a temporary file, and with various shellcommands I shouldn't even have available on the machine in question (diff among them).

I am desperately looking for a solution which is maintainable even when (potentially) updating hundreds of lines in a file.

Please also see my additions inserted between the quotes below:


Josef Wolf [u] wrote on 02/09/2004 14:25:

On Thu, Sep 02, 2004 at 01:52:12PM +0200, Sven Mueller wrote:




test:x:1:1::/tmp/:/bin/bash
test2:x:2:2::/tmp/:/bin/bash

Here is what cfagent.conf looks like:

control:
     actionsequence = ( editfiles )

editfiles:
     { /tmp/passwd
             Backup "Off"
             SplitOn ":"
             ReplaceLinesMatchingField 1
             SetLine "test::::::"
             AppendIfNoLineMatching "ThisLine"
     }

AFAICS, the ThisLine notation works only in a ForEachLineIn loop.

Hmm, this didn't make a difference. Also, the documentation says:
'If "ThisLine" is given as the argument, the current value of the line buffer is assumed.'
The documentation of "ForEachLineIn" says:
'The result is like using SetLine for each line in the file'
And while the SetLine documentation says nothing about a line buffer (but ForEachLineIn doesn't either), what I gather from the above two snippets is that 'AppendIfNoLineMatching "ThisLine"' should do exactly what I expected. But it doesn't.


You need to give a regexp to AppendIfNoLineMatching. Further,
ReplaceLinesMatching requires either a ForEachLineIn loop or a

SetLine.

So please try:

       { /tmp/passwd
               Backup "Off"
               SplitOn ":"
               SetLine "test::::::"
               ReplaceLinesMatchingField 1
               AppendIfNoLineMatching "test:.*"
       }

Changing it this way still doesn't replace an existing "test:x:1:1::/tmp/:/bin/bash" line with the "test::::::" line. It doesn't seem to matter wether the ReplaceLinesMatchingField instruction is given before or after SetLine. It doesn't do what the documentation suggests in either case.

I'm really out of wits on this problem.

cu,
sven


_______________________________________________
Help-cfengine mailing list
Help-cfengine@gnu.org
http://lists.gnu.org/mailman/listinfo/help-cfengine





reply via email to

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