Forum: Cfengine Help
Subject: search and replace help
Author: neilhwatson
Link to topic: https://cfengine.com/forum/read.php?3,20275,20275#msg-20275
Dear all,
I'm trying to build a policy that will search and replace shell history size in
a profile file. I did not see a generic search and replace in the standard
library so I'm attempting to roll my own using Community 3.1.2. Relevant snips
vars:
linux::
"histsize" string => "7200",
comment => "Shell history size to insert.";
files:
linux::
"/tmp/profile.suse"
handle => "Replace_Shell_CLI_history",
comment => "Replace shell history",
classes => cdefine(
"replace_hist_kept",
"replace_hist_repaired",
"replace_hist_failed"
),
edit_line => search_replace(
"HISTSIZE=(?!${histsize})",
"HISTSIZE=${histsize}");
bundle edit_line search_replace(string1, string2) {
replace_patterns:
"${string1}"
replace_with => replace_last("${string2}");
}
body replace_with replace_last(string2) {
replace_value => "${string2}";
occurrences => "all";
}
Syntax checks out. But results are not what I would expect.
Before:
if test -z "$PROFILEREAD" ; then
HISTSIZE=200
export HISTSIZE
fi
and after:
if test -z "$PROFILEREAD" ; then
HISTSIZE=7200200
export HISTSIZE
fi
Why is the 200 preserved?
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine