Re: regex quirks

Xander Cage <[email protected]>
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>
when i negate the regex the info message is gone, but no edits are 
done...causality dilemma. 

bundle edit_line itsv_modify_cron_line ( _find, _replace )
# @brief modify lines matching a regular expression eg. ".*\/usr\/bin\/nmon 
-F \/var\/log\/nmon.*1.*"
# @param _find The regular expression that the lines need to match
# @param _replace String to substitute `_find` with
{

  replace_patterns:

   "^(?!$(_find))$"
     replace_with => value("$(_replace)");

#   delete_lines:
#
#      "^($(_find))$";
#
#   insert_lines:
#
#     "$(_replace)";


}


On Tuesday, August 3, 2021 at 1:22:49 PM UTC+2 [email protected] 
wrote:

> On Wed, 2021-07-28 at 07:29 -0700, Xander Cage wrote:
> > 
> > hey,
> > 
> > i'm toying  around in making a bundle for crontab editing (add,
> > modify, remove) and regex is
> > beginning to bite me.
> > 
> > i got an "informational" message that my pattern matching skills are
> > downlevel.
> > 
> > /var/cfengine/bin/cf-agent -KI -f ./nmon_cron_test.cf
> >     info: Promised replacement '0 0 * * * /usr/bin/nmon -F
> > /var/log/nmon/`hostname`_`date +'\%y\%m\%d_\%H\%M'`.nmon -s 300 -c
> > 288 1>/dev/null 2>/dev/null' for pattern '^.*/usr/bin/nmon -F.*$' is
> > not properly convergent while editing '/var/spool/cron/crontabs/root'
> >     info: Because the regular expression '^.*/usr/bin/nmon -F.*$'
> > still matches the end-state replacement string '0 0 * * *
> > /usr/bin/nmon -F /var/log/nmon/`hostname`_`date
> > +'\%y\%m\%d_\%H\%M'`.nmon -s 300 -c 288 1>/dev/null 2>/dev/null'
>
> The 'info' message explains what the problem is -- the anchor regular
> expression matches the replacement string. That means the promise
> doesn't converge -- it will make a change every time it is evaluated.
> That's generally considered a bad pattern in CFEngine (and any engine
> based on state specification instead of action specification).
>
> You can ignore the message or, ideally, change the regex to only match
> the undesired state.
>
> Thanks.
>
> --
> Vratislav
>

-- 
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/3e0014a6-dea2-4514-910c-56f0531084b7n%40googlegroups.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.