I'm learning BASH and trying to create a script that generates a configuration file in which I want to use variables. But of course, like this is a text file, the variable ${MONGO_PORT} is not being replaced by the value i need.
(
cat << MONGOD_CONF
# /etc/mongod.conf
systemLog:
destination: file
path: /datos/log/mongod.log
logAppend: true
storage:
dbPath: /datos/db
engine: wiredTiger
net:
port: ${MONGO_PORT}
security:
authorization: enabled
MONGOD_CONF
) > /etc/mongod.conf
The first problem is about permission to create the file that I'm avoiding by creating the file in /tmp and moving it to /etc. Because this doesn't work.
sudo cat << MONGOD_CONFThe second and more important is about how to replace de variable by the value
Any way to make this work?
Thank you!