help-cfengine
[Top][All Lists]
Advanced

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

Re: Editfiles, DeleteCommands, POSIX Syntax, etc


From: Andrew Stribblehill
Subject: Re: Editfiles, DeleteCommands, POSIX Syntax, etc
Date: Thu, 10 Apr 2003 12:43:10 +0100
User-agent: Mutt/1.5.4i

Quoting Brian E. Seppanen <seppy@chartermi.net> (2003-04-10 12:24:25 BST):
> On Thu, 10 Apr 2003, Andrew Stribblehill wrote:
> 
> > Quoting Brian E. Seppanen <seppy@chartermi.net> (2003-04-09 08:39:29 BST):
> > > Hello:
> > > 
> > > I'm desperate to use editfiles for some ACL maintanence, and to do so I
> > > need to insure that I can clear a couple of lines with the DeleteCommands,
> > > unfortunately I cannot, for the life of me, define a regex or pattern that
> > > will match, and I'm frankly baffled.  I need to match
> > > 
> > >   only_from       += 192.168.0.0/24
> > > 
> > > In all cases I've been careful to escape the + and the .'s   I've had 
> > > luck 
> > > with a BeginGroupIfNoMatch, so I'm pretty sure, I haven't missed escaping 
> > > something.
> > 
> > Cfengine uses regular expressions in a 'tied' manner i.e. the whole
> > line must match the regular expression. So, try this:
> > 
> > DeleteLinesMatching '^only_from +\+= 129\.168\.0\.0/24$'
> > 
> > The ^ and $ are optional but I like them there to remind me what's
> > going on.
> 
> How can I express tabs in the expression?  Is there a regex that is clever
> enough to handle an unlimited number of IP's?  What I mean by an
> unliminited number of IP's is if I have something like 192.168.0.0/24
> 10.0.0.0/8 172.19.0.0/16 is there a regular expression that could match 
> multiple's in a single definition.   

Tabs are $(tab) -- not part of the regular expression language, but
interpolated by Cfengine before that stage.

> 
> something like
> 
> ^only_from\+= 
> ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]{1,2})*$
> 
> I hope that makes some sense.

I'd be lazy and go for:

^only_from[ $(tab)]*+=([ $(tab)]*([0-9.]+(/[0-9]+)?))+$

That matches:
only_from += 1.2.3.4
only_from += 1.2.3.4/24 5.6.7.8/83
only_from += 1..2./100

It all depends why you want to match as to how exacting you need your
regular expression to be. If you're not very likely to have malformed
IP addresses around don't worry about it.

-- 
HEBRIDES BAILEY
SOUTHERLY VEERING NORTHWESTERLY 4 OR 5. RAIN OR SHOWERS. MODERATE
OR GOOD




reply via email to

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