help-cfengine
[Top][All Lists]
Advanced

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

Re: Need for the same set of commands for Insert as well as Append


From: Tim Nelson
Subject: Re: Need for the same set of commands for Insert as well as Append
Date: Mon, 31 Oct 2005 11:17:47 +1100 (EST)

On Sun, 30 Oct 2005, Marco van Beek wrote:

Hi All,

I think there is a need for the same sort of flexibility that the AppendIf... commands within editfiles gives us, but as an insert, so that they can be specified in an exact place.

I am modifying shorewall config files which require a final line that says "THIS IS THE LAST LINE". I need to place all my edits above this line, and ideally what I would do is to use InsertFromFileIfNoSuchLines, or an InsertIfNoSuchLine "ThisLine" in a ForEachLineIn loop.

I could use the standard append commands, and then locate the "last" line, delete and then append it, but that isn't exactly tidy or necessarily reliable, as I would have to run it in a separate loop under a separate class defined by first loop.

The only other way I can think of doing it is to nest a group and a group:

        {
        /file-to-be-edited
                ForEachLineIn "data-file"
                        BeginGroupIfNoSuchLine "ThisLine"
                                EmptyEntireFilePlease
                                Append "# File Header & Comments"
                                InsertFile "datafile"
                                Append "# THIS IS THE LAST LINE"
                        EndGroup
                EndLoop
                DefineClasses "restart_shorewall"
                }

        What about something like this:

        ResetSearch 0
        LocateLineMatching ".*THIS IS THE LAST LINE.*"
        BeginGroupIfNoSuchLine "ThisLine"
                InsertFile "datafile"
        EndGroup
        CatchAbort


within shorewall that may allow me to have a much simpler file to edit, but having an InsertIf.. set of commands may be a worthy addition to CFEngine. Just don't ask me to write it, I wouldn't know where to start. ;)

Everyone agrees editfiles needs work. But the only plans afoot are for cfengine 3, unless someone volunteers :).

--
Kind Regards,
 
Tim Nelson
Server Administrator
 
P: 03 9934 0888
F: 03 9934 0899
E: tim.nelson@webalive.biz
W: www.webalive.biz
 
WebAlive Technologies
Level 1, Innovation Building
Digital Harbour
1010 La Trobe Street
Docklands Melbourne VIC 3008

This email (including all attachments) is intended solely for the named 
addressee. It is confidential and may contain legally privileged information. If
you receive it in error, please let us know by reply email, delete it from your 
system and destroy any copies. This email is also subject to copyright. No
part of it should be reproduced, adapted or transmitted without the written 
consent of the copyright owner.

Emails may be interfered with, may contain computer viruses or other defects 
and may not be successfully replicated on other systems. We give no
warranties in relation to these matters. If you have any doubts about the 
authenticity of an email purportedly sent by us, please contact us immediately.

reply via email to

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