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.
To create a new file, run the "cat" command and then use the redirection operator ">" followed by the name of the file. Now you will be prompted to insert data into this newly created file. Type a line and then press "Ctrl+D" to save the file.
A basic Bash script has three sections. Bash has no way to delineate sections, but the boundaries between the sections are implicit. All scripts must begin with the shebang (#!), and this must be the first line in any Bash program. The functions section must begin after the shebang and before the body of the program.
Use your template to create a new document To start a new document based on your template, on the File menu, click New from Template, and then select the template you want to use.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With