help-cfengine
[Top][All Lists]
Advanced

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

Re: editfiles question


From: Ed Brown
Subject: Re: editfiles question
Date: Wed, 01 Sep 2004 08:44:44 -0600

Here's another approach:

editfiles:
   { /etc/whatever
          BeginGroupIfNoLineMatching "root:$1raboof:4875::::::"
                 LocateLineMatching "^root:.*"
                 ReplaceLineWith "root:$1raboof:4875::::::"
          EndGroup
   }

-Ed




On Wed, 2004-09-01 at 08:28, Sven Mueller wrote:
> 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
> 
> 
> _______________________________________________
> 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]