[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Editfiles hack
From: |
Tim Nelson |
Subject: |
Re: Editfiles hack |
Date: |
Mon, 29 Mar 2004 10:23:11 +1000 (EST) |
On Sat, 27 Mar 2004, Russell Adams wrote:
> I've started using the following for most of my config files. I kind
> of felt it was a dirty hack, so I thought I'd ask if anyone else was
> doing the same or had suggestions.
>
> I'll use an editfiles command like the one below, basically it looks
> for a revision number as the first line of the file. If it doesn't
> match, then the entire file contents is replaced.
Hmm. I'd tend to do something like:
BeginGroupIfNoLineMatching "# interfaces v1.02"
DefineInGroup "replaceinterfaces"
EndGroup
...and then in the copy section, just copy it from the central
server.
>
> { /etc/network/interfaces
>
> AutoCreate
>
> BeginGroupIfNoLineMatching "# interfaces v1.02"
> EmptyEntireFilePlease
> Append "# interfaces v1.02"
> Append ""
> Append "auto lo"
> Append "iface lo inet loopback"
> Append ""
> Append "auto eth0"
> Append "iface eth0 inet static"
> Append " address 192.168.1.170"
> Append " netmask 255.255.255.0"
> Append " network 192.168.1.0"
> Append " broadcast 192.168.1.255"
> Append " gateway 192.168.1.254"
> Append ""
> EndGroup
> }
>
> Part of this was caused by my recent frustration trying to replace
> individual lines in the above config file in a reliable manner. (ie:
> replace address, but not all addresses...)
Sounds like you need a ReplaceIfNoLineMatching. I munge all my
cfengine configs with Perl on the server. So I'd just do:
<? ReplaceIfNoLineMatching('^\s+address .*$', "\taddress
192.168.1.170") ?>
..and Perl would munge it for me into something like:
(parameter 1 is $searchterm, parameter 2 is $text)
----------------------------
ResetSearch "1"
LocateLineMatching "$searchterm"
BeginGroupIfNoLineMatching "$text"
InsertLine "$text"
EndGroup
CatchAbort
----------------------------
I actually go through about three function calls to achieve this
output, since some of the code is the same as eg. InsertAfterIfNoSuchLine,
and I allow for multiple lines to be inserted, instead of just $text
While we're on the subject of editfiles, Mark, do you have time
yet to continue our discussion? (Yeah, I ask these things just to annoy
you :o) ).
Thanks all,
--
Tim Nelson
Systems Administrator
Sunet Internet
Tel: +61 3 5241 1155
Fax: +61 3 5241 6187
Web: http://www.sunet.com.au/
Email: sysadmin@sunet.com.au