help-cfengine
[Top][All Lists]
Advanced

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

Re: editfiles question


From: Sven Mueller
Subject: Re: editfiles question
Date: Wed, 01 Sep 2004 16:28:15 +0200
User-agent: Thunderbird 0.7.3 (Windows/20040803)

Jamie Wilkinson [u] wrote on 31/08/2004 16:05:

This one time, at band camp, Sven Mueller wrote:

From the documentation, I am not certain how to achieve the following task. Let's say I want to edit /etc/passwd (actually I am editing a similarly formated, but different file), and I want the following to be achieved:

- I want the file to be created if it doesn't exist (AutoCreate takes
care of this)
- I want a line "root:..1234567890123:0:0::/bin/bash" be added to the
file if it doesn't exist, overwriting any root:.* lines that might
exist.

http://shipyard.com.au/shipyard/articles/sysadmin/cfengine-configfiles.py

OK, I must have misread that page the first time, coming to the result that it didn't achieve what I wanted: Editing the file only if the line I want in there isn't there or when I need to replace lines matching its first field. Jamie corrected this impression via private email. However, the construct given on that page seems a bit too complex for such a seemingly easy task. Here is what the page gives as to what one needs to do (translated to editing /etc/passwd):

{ /etc/ssh/sshd_config
      Backup 'off'

      BeginGroupIfNoLineMatching '^root:.*'
        Append 'root:x:0:0::/bin/bash'
      EndGroup
      ResetSearch 1
      LocateLineMatching '^root.*'
      BeginGroupIfNoMatch '^root:x:0:0::/bin/bash$'
        ReplaceLineWith 'root:x:0:0::/bin/bash'
      EndGroup
)

Now, this seems a bit too much just to replace matching lines by the line wanted, appending or prepending the wanted line if no matching line was found. In the given case (/etc/passwd), would this be enough?

{ /etc/passwd
        Backup 'off'
        ReplaceLinesMatchingField 1
        SetLine "root:x:0:0::/bin/bash"
        # The above should already replace any line with
        # a matching first field ("root"), right?
        AppendIfNoLineMatching "ThisLine"
        # which should append the line previously set by "SetLine"
        # if no matching line is in the file yet, right?
}

If nobody can say for certain, I will have to try this in some way.

cu,
sven



reply via email to

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