I have to create conf files and init.d
which are very similar. These files permit to deploy new http service on my servers. These files are the same and only some parameters change from one file to another (listen_port
, domain, path on server...).
As any error in these files leads to misfunction of service I would like to create these files using a bash script.
For example:
generate_new_http_service.sh 8282 subdomain.domain.com /home/myapp/rootOfHTTPService
I am looking for a kind of templating module that I could use with bash. This templating module would use some generic conf and init.d scripts to create new ones.
Do you have hints for that? If not I could use python templating engine.
You can do this using a heredoc. e.g.
generate.sh:
#!/bin/sh
#define parameters which are passed in.
PORT=$1
DOMAIN=$2
#define the template.
cat << EOF
This is my template.
Port is $PORT
Domain is $DOMAIN
EOF
Output:
$ generate.sh 8080 domain.com
This is my template.
Port is 8080
Domain is domain.com
or save it to a file:
$ generate.sh 8080 domain.com > result