regex quirks
Xander Cage <[email protected]>
| Newsgroups | gmane.comp.sysutils.cfengine.general |
|---|---|
| Message-ID | <[email protected]> |
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'
info: Promise belongs to bundle 'itsv_modify_cron_line' in file
'./nmon_cron_test.cf' near line 99
R: Time: Wed Jul 28 16:19:05 2021 - Bundle: do_what_i_say - Message: cron
line found
can i ignore this? not sure.
heres the policy code, maybe someone can look over it....
body file control
{
inputs => { "$(sys.libdir)/stdlib.cf"
};
}
bundle agent do_what_i_say
{
vars:
"cron_line" 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";
"root_cron_file" string => "/var/spool/cron/crontabs/root";
"find_anchor" string => "^.*/usr/bin/nmon -F.*$";
"file_content"
string => readfile( "$(root_cron_file)" , inf ),
if => not( isvariable( $(this.promiser) ) );
classes:
"cron_line_found"
expression => regcmp( $(find_anchor),
$(file_content));
"cron_line_not_found"
expression => not( regcmp( $(find_anchor),
$(file_content)));
files:
"$(root_cron_file)"
comment => "Promise root cron table entries",
create => "true",
classes => results( "bundle", "itsv_modify_cron_line" ),
if => cron_line_found,
perms => mog("0600","root","cron"),
edit_line => itsv_modify_cron_line("$(find_anchor)",
$(cron_line));
"$(root_cron_file)"
comment => "Promise root cron table entries",
create => "true",
classes => results( "bundle", "itsv_add_cron_line" ),
if => cron_line_not_found,
perms => mog("0600","root","cron"),
edit_line => itsv_add_cron_line($(cron_line));
commands:
itsv_modify_cron_line_repaired|itsv_add_cron_line_repaired::
"/usr/bin/crontab"
args => "$(root_cron_file)",
comment => "Reread cron tables if it was edited.";
reports:
cron_line_found::
"Time: $(sys.date) - Bundle: $(this.bundle) - Message: cron line
found";
cron_line_not_found::
"Time: $(sys.date) - Bundle: $(this.bundle) - Message: cron
line not found";
itsv_modify_cron_line_repaired|itsv_add_cron_line_repaired::
"Time: $(sys.date) - Bundle: $(this.bundle) - Message: reloaded cron
with file $(root_cron_file)";
}
bundle edit_line itsv_add_cron_line ( line )
# @brief append lines if they don't exist
# @param line The regular expression that the lines need to match
{
insert_lines:
"$(line)"
comment => "Append lines if they don't exist";
}
bundle edit_line itsv_modify_cron_line ( _find, _replace )
# @brief modify lines matching a regular expression eg. "^.*/usr/bin/nmon
-F.*$"
# @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)");
}
bundle edit_line itsv_delete_cron_line ( regex )
# @brief delete lines matching a regular expression eg. "^.*/usr/bin/nmon
-F.*$"
# @param regex The regular expression that the lines need to match
{
delete_lines:
"$(regex)"
comment => "Delete lines matching the marker";
}
bundle agent __main__
{
methods: "do_what_i_say";
}
wbr
chris
--
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/ef582926-d00a-4c52-a090-83618481f66cn%40googlegroups.com.