Hi there. I tend to write a lot of shell scripts to do installations and configurations of varios Linux software. Now because I want to dynamically write config files for systems (say for example postfix, etc), I am trying to figure out the most effective way to accomplish this. Does anyone have any suggestions? I would hate to have to write out echo statements. I would like to maybe have a "template" file in which the script would make a copy and substitute variables in the final output config file.
I was thinking of something like:
# a var used in the template config file
declare -rx MYDB="postfix"
# a template config file
declare -rx TEMPATECFG="my.template.conf"
# The final config file with proper substitutions
declare -rx TMPFILE="my.conf"
# read in the template
while read curline; do
echo "$curline" >> $TMPFILE
done < my.temnplate.conf
Then in my template file I would have something like:
grant SELECT ON $MYDB.* to 'postfix'@'localhost' IDENTIFIED by 'somePass';
The actual code in the template file is really irrelevant to this question, and I was just providing an example.
Now obviously the above code does not work as the variable substitution does not happen.
So I guess I am just hoping to get a pointer on how others may have done this kind of thing.
Ultimately I just want to write dynamic config files.