help-cfengine
[Top][All Lists]
Advanced

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

Re: editfiles and replacing on one line


From: Viraj Alankar
Subject: Re: editfiles and replacing on one line
Date: Mon, 7 Nov 2005 06:59:38 -0500

On 11/7/05, Mark Burgess <address@hidden> wrote:
>
> How would you do it is perl? With a regular expression?
> If the problem is that you don't really know what you are looking for,
> or what the result should look like, then it seems to me that trying to
> do it in perl will not help you either. Perhaps this is where the
> problem lies...

I would do the following:

perl -pi -e 's/(\s+\/tmp.*),noexec/$1/' /etc/fstab

The main issue is I do not know what the mount device may be. I just
know the mount point is /tmp and if it has noexec I would like to
remove it.

Viraj.

> On Sun, 2005-11-06 at 21:07 -0500, Viraj Alankar wrote:
> > Thanks. So I guess there is no way if I don't know what the exact line
> > will look like? Basically I could do a 'perl -pie' but was hoping I
> > could do it within cfengine.
> >
> > Viraj.
> >
> > On 11/6/05, Brendan Strejcek <address@hidden> wrote:
> > > Viraj Alankar wrote:
> > >
> > > > ...
> > > > /dev/sda2               /tmp                    ext3
> > > > defaults,nosuid,nodev,noexec        1 2
> > > > ...
> > > >
> > > > I would like to remove ',noexec' from this line only. I thought of
> > > > using LocateLineMatching to find the line, but am not sure how to do
> > > > the replacement.
> > >
> > > Here is a very careful way to do it, though it requires that you know
> > > the entire form of the line you want to end up with.
> > >
> > > control:
> > >     fstab_line = ( "/dev/sda2 /tmp ext3 defaults,nosuid,nodev 1 2" )
> > >
> > > editfiles:
> > >     { /etc/fstab
> > >         AppendIfNoSuchLine "${fstab_line}"
> > >         ResetSearch "1"
> > >         LocateLineMatching "^/dev/sda2.*$"
> > >         BeginGroupIfNoMatch "^${fstab_line}$"
> > >             ReplaceLineWith "${fstab_line}"
> > >         EndGroup
> > >         DeleteLinesAfterThisMatching "^/dev/sda2.*$"
> > >         CatchAbort
> > >     }
> >
> >
> > _______________________________________________
> > Help-cfengine mailing list
> > address@hidden
> > http://lists.gnu.org/mailman/listinfo/help-cfengine
>
>




reply via email to

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